开发者

UNIX, Assign value to a variable in C or KornShell (ksh)

When I use bash to run the following code, it will assign the value 5 to the var1.

var1=$(awk '$1>$3{ print "5"}' newfile2)
echo $var1

But when I use this same code in banana or something, it gives me error. Can someone please tell me if there is some other way I can write this code so I can ru开发者_StackOverflown it using the C or KornShell (ksh) as well.


For C shell, use

set var=`....`

For bash/ksh

var1=$(awk '$1>$3{ print "5"}' newfile2)


Use backticks and the set command for csh.

set var1=`awk '$1>$3{ print "5"}' newfile2`
echo $var1


Please note that there are no spaces before and after the variable name. so,

var1=`ls`

is what you need. But, if you have

var = `ls` 

you will get errors.

So, your code should be:

var1=`awk '$1>$3{ print "5"}' newfile2`
echo $var1

Make sure you are in BASH shell, not C or TCSH.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜