Cannot pass rsh and awk command into a variable

Hello,

I'm having some issues getting a home dir from a remote server passed to a variable.

Here is what I have so far:

rsh server "(ls -ld /home*/user | awk '{print \$9}')"
/home3/user

That works fine and brings back what I need.

But when I try to add it to a variable it goes all wrong!

HOMEDIR=`rsh server "(ls -ld /home*/user| awk '{print \$9}')"`
print $HOMEDIR
drwxrwsrwx 2 user staff 512 12 Oct 2011 /home3/user

Can anyone please explain what's going wrong?

Many thanks,
P.

There's no point listing the permissions, user and group ownership, file size, and modification time when you're going to just strip that all back out with awk. Simplifying that statement may help it work, so try this:

VAR=`rsh server "(ls -d /home*/user)"`
1 Like

Haha true, well spotted.

I'd still like to know how to do it though, just for closure.

Thanks
P.

I'm not 100% positive. It may be the way backticks `` allow splitting, if your shell supports $( ) syntax that may cause less problems.

1 Like