|
Prev: simple sed script
Next: POSIX compilant function call
From: jaredsubman on 19 Jun 2008 12:04 In bash, why does this form of tilde home directory expansion work fine: ls -ld ~joeuser drwxr-xr-x 7 joeuser joeuser 512 Jun 11 11:03 /usr/home/joeuser/ yet, if I set the username to a variable, and try to use tilde expansion, it never happens: e.g. USERNAME="joeuser" ls -ld ~$USERNAME ls: ~joeuser: No such file or directory I've tried MANY variants of the above (including ls -ld ~{$USERNAME}) with no luck. Any help would be much appreciated. Thanks in advance.
From: Dave B on 19 Jun 2008 12:15 jaredsubman(a)yahoo.com wrote: > In bash, why does this form of tilde home directory expansion work > fine: > > ls -ld ~joeuser > > drwxr-xr-x 7 joeuser joeuser 512 Jun 11 11:03 /usr/home/joeuser/ > > yet, if I set the username to a variable, and try to use tilde > expansion, it never happens: > > e.g. > USERNAME="joeuser" > ls -ld ~$USERNAME > ls: ~joeuser: No such file or directory That's probably because tilde expansion happens before variable expansion, not after. A solution is using eval: eval ls -ld ~$USERNAME as usual when using eval, be sure to always know what's inside USERNAME and that it's a valid value. -- echo 0|sed 's909=oO#3u)o19;s0#0ooo)].O0;s()(0bu}=(;s#}#.1m"?0^2{#; s)")9v2@3%"9$);so%op]t(p$e#!o;sz(z^+.z;su+ur!z"au;sxzxd?_{h)cx;:b; s/\(\(.\).\)\(\(..\)*\)\(\(.\).\)\(\(..\)*#.*\6.*\2.*\)/\5\3\1\7/; tb'|awk '{while((i+=2)<=length($1)-18)a=a substr($1,i,1);print a}'
From: Sashi on 19 Jun 2008 12:39 > echo 0|sed 's909=oO#3u)o19;s0#0ooo)].O0;s()(0bu}=(;s#}#.1m"?0^2{#; > s)")9v2@3%"9$);so%op]t(p$e#!o;sz(z^+.z;su+ur!z"au;sxzxd?_{h)cx;:b; > s/\(\(.\).\)\(\(..\)*\)\(\(.\).\)\(\(..\)*#.*\6.*\2.*\)/\5\3\1\7/; > tb'|awk '{while((i+=2)<=length($1)-18)a=a substr($1,i,1);print a}' Does this signature have any meaning? I ran it by the bash prompt with GNU sed and awk and it gave an error.
From: Dave B on 19 Jun 2008 12:40 Sashi wrote: >> echo 0|sed 's909=oO#3u)o19;s0#0ooo)].O0;s()(0bu}=(;s#}#.1m"?0^2{#; >> s)")9v2@3%"9$);so%op]t(p$e#!o;sz(z^+.z;su+ur!z"au;sxzxd?_{h)cx;:b; >> s/\(\(.\).\)\(\(..\)*\)\(\(.\).\)\(\(..\)*#.*\6.*\2.*\)/\5\3\1\7/; >> tb'|awk '{while((i+=2)<=length($1)-18)a=a substr($1,i,1);print a}' > > Does this signature have any meaning? I ran it by the bash prompt with > GNU sed and awk and it gave an error. Yes, it should work just fine. Just do copy/paste. What error do you get? -- echo 0|sed 's909=oO#3u)o19;s0#0ooo)].O0;s()(0bu}=(;s#}#.1m"?0^2{#; s)")9v2@3%"9$);so%op]t(p$e#!o;sz(z^+.z;su+ur!z"au;sxzxd?_{h)cx;:b; s/\(\(.\).\)\(\(..\)*\)\(\(.\).\)\(\(..\)*#.*\6.*\2.*\)/\5\3\1\7/; tb'|awk '{while((i+=2)<=length($1)-18)a=a substr($1,i,1);print a}'
From: Michael Tosch on 19 Jun 2008 13:54 jaredsubman(a)yahoo.com wrote: > In bash, why does this form of tilde home directory expansion work > fine: > > ls -ld ~joeuser > > drwxr-xr-x 7 joeuser joeuser 512 Jun 11 11:03 /usr/home/joeuser/ > > yet, if I set the username to a variable, and try to use tilde > expansion, it never happens: > > e.g. > USERNAME="joeuser" > ls -ld ~$USERNAME > ls: ~joeuser: No such file or directory > > I've tried MANY variants of the above (including ls -ld ~{$USERNAME}) > with no luck. > > Any help would be much appreciated. Thanks in advance. Either HOMEDIR=~joeuser ls -ld "$HOMEDIR" or USERNAME="joeuser" eval ls -ld ~$USERNAME -- echo imhcea\.lophc.tcs.hmo | sed 's2\(....\)\(.\{5\}\)2\2\122;s1\(.\)\(.\)1\2\11g;1s;\.;::;2'
|
Pages: 1 Prev: simple sed script Next: POSIX compilant function call |