3

My Problem

My core issue is I need to start the gnome-keyring-daemon from c shell. In bash, it's quite easy:

> export `gnome-keyring-daemon`

which is the equivalent of:

> export GNOME_KEYRING_SOCKET=/tmp/0123.1.sds/keyring-abcdef/socket GNOME_KEYRING_PID=012345

My goal is to get the same functionality in c shell, but my command line skills aren't 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 get a good start:

setenv GNOME_KEYRING_SOCKET /tmp/0123.1.sds/keyring-abcdef/socket ;setenv GNOME_KEYRING_PID 012345

Despite the fact that i can copy and paste that output to the command line and get it to work, if I enclose that statement in ticks to get it working on one line I get the following error:

Invalid null command.

I researched it and saw it is related to a newline sneaking in that needs to be escaped or removed; however, I still get the error even after adding replace commands for \r and \n like so:

> | tr '\r' ' ' | tr '\n' ' ' |

What I'm looking for

I really just need anything I can add to my .cshrc file that will start the gnome-keyring-daemon. If I'm on the wrong track, I'd be happy to hear an alternative approach.

Thanks!

One Last Thing I Tried

To really simplify this I've 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 a "Invalid null command." message despite the fact that this works:

setenv GNOME_KEYRING_PID `echo '1234'`
Michael La Voie
  • 27,772
  • 14
  • 72
  • 92
  • Don't know what to say about null command, but you can chain all of the sed stuff into one invocation, possibly reducing places for null commands to creep in ;-) . i.e. `echo gnome-keyring-daemon | sed 's/=//;s/GNOME_KEYRING_SOCKET/setenv GNOME_KEYRING_SOCKET/; s/GNOME_KEYRING_PID/;setenv GNOME_KEYRING_PID/'` Hmm, been a while since I did complex csh stuff. possibly the null is being inserted by the backtick processing, so adding `tr '\r' ''` etc won't defeat that problem. Also, are you sure that code is working, not sure any/all `tr`s know about '\r', so try octal i.e. `'\015'`.Good luck. – shellter Mar 21 '12 at 19:17
  • ok, in your one-last-thing block, did you really mean to have backtick echo -n backtick etc? When you use four spaces indent to get 'code formatting', you don't need to add backticks to do formatting. What I see now says 'command substitution for echo -n' (using back ticks), string=gnome-key-ring-daemon 'command sub for | sed ...' You just want 1 set of back tics on that commandline right? (I know it's hard to get these to work right in the editor). Good luck. – shellter Mar 21 '12 at 19:30

2 Answers2

2

Thanks to @shelter and @gbulmer for your help. I really hate answering my own question, but this may 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
Michael La Voie
  • 27,772
  • 14
  • 72
  • 92
1

Have you tried echo -n gnome-keyring-daemon | ... echo adds a newline

gbulmer
  • 4,210
  • 18
  • 20