I have the following line at the first line in my script file:
#!/bin/sh
So I'm using csh.(?)
I wanto assign the output of the following to an environment variable:
echo $MYUSR | awk '{print substr($0,4)}'
I try:
set $MYVAR = echo $MYUSR | awk '{print substr($0,4)}'
But it doesn't work,
How can I do it? I want to do it in a sh file.
Best Answer
Your script should look like
I don't have a way to test this right now, let me now if it doesn't work.
If you've inherited the basis of your script from someone else, with the
#!/bin/sh
, then you have to find out if /bin/sh is really the bourne shell, or if it is a link to /bin/bashYou can tell that by doing
if you get back information on files where the size is exactly the same, the you're really using bash, but called as /bin/sh
So try these 2 solutions
AND
in all cases (csh) included, the back-ticks AND the
$( ... )
are known as command substitution. What every output comes from running the command inside, is substituted into the command line AND then the whole command is executed.I hope this helps.