How to setenv based on sed results (for gnome-keyring-daemon)
My problem
My main problem: I need to run gnome-keyring-daemon from c shell. In bash, it's pretty straightforward:
> export `gnome-keyring-daemon`
which is equivalent to:
> export GNOME_KEYRING_SOCKET=/tmp/0123.1.sds/keyring-abcdef/socket GNOME_KEYRING_PID=012345
My goal is to get the same functionality in a c shell, but my command line skills are not up to the task.
What i tried
If I run
echo
gnome-keyring-daemon
| tr '=' '' | sed s / GNOME_KEYRING_SOCKET / setenv \ GNOME_KEYRING_SOCKET / | sed s / GNOME_KEYRING_PID / \; setenv \ GNOME_KEYRING_PID /
I start well:
setenv GNOME_KEYRING_SOCKET /tmp/0123.1.sds/keyring-abcdef/socket ;setenv GNOME_KEYRING_PID 012345
Even though I can copy and paste this output into the command line and get it to work, if I wrap this statement in ticks to make it work on one line, I get the following error:
Invalid command null.
I researched it and saw that it has to do with a newline in that needs to be escaped or deleted; however, I still get the error even after adding replace commands for \ r and \ n like so:
> | tr '\r' ' ' | tr '\n' ' ' |
What i am looking for
I really need something that I can add to my .cshrc file that will run the gnome-keyring-daemon. If I'm wrong, I'd love to hear an alternative approach.
Thank!
One last thing I tried
To really simplify this, I also tried to just set one variable at a time:
setenv GNOME_KEYRING_PID `echo -n `gnome-keyring-daemon` | sed 's/.*GNOME_KEYRING_PID=\([0-9]\+\)/\1/'`
Which also gives me the "Invalid null command". even though this works:
setenv GNOME_KEYRING_PID `echo '1234'`
source to share
Thanks @shelter and @gbulmer for your help. I really hate answering my own question, but it might help someone in the future ...
In the end, I updated my C Shell script to set the variables on multiple separate lines:
set gkd = `gnome-keyring-daemon`
set pid = `echo $gkd | sed 's/.*GNOME_KEYRING_PID=\([0-9]\+\)/\1/'`
set socket = `echo $gkd | sed 's/GNOME_KEYRING_SOCKET=\([^ ]\+\).\+/\1/'`
setenv GNOME_KEYRING_PID $pid
setenv GNOME_KEYRING_SOCKET $socket
source to share