English 中文(简体)
k 不按背书标准评价变量
原标题:ksh not evaluating variable within backticks

我 st。

#!/bin/ksh

AWKSCRIPT= END { print "all done"; } 

OUTPUT=`echo hello world | awk  $AWKSCRIPT `

RETVAL=$?

echo "running echo hello world | awk  $AWKSCRIPT "
echo "Output = $OUTPUT"
echo "returned = $RETVAL"

产出

$ ./kshawk.ksh
Output = hello world
returned = 0

(我期待看到“Output = 一切已完成”)

它认为,口译人员在评估表述时并不取代AWKSCRIPT变量(如果我使用(......)美元而不是背书,我会采取同样的行为)。

虽然我可以把AWKSCRIPT放在临时档案中,但这也必须硬化吗?

Any ideas how to interpolate a variable within backticks?

最佳回答

The single quotes around $AWKSCRIPT prevent the interpolation of the variable. Double quotes do allow interpolation:

$ OUTPUT=`echo hello world | awk "$AWKSCRIPT"`
$ echo $OUTPUT
all done
问题回答

暂无回答




相关问题
How can I flush the input buffer in an expect script?

I m writing an Expect script and am having trouble dealing with the shell prompt (on Linux). My Expect script spawns rlogin and the remote system is using ksh. The prompt on the remote system contains ...

changing to parent directory in unix

in general we use cd .. for going to the parent directory cd ../../ to go to the parents parent directory. and cd ../../../../../ for 5th parent directory. is there any simplified way of doing ...

$$ in KornShell

What is the meaning of $$ in KornShell? I guess it is associated with the process ID, but I want to know its exact meaning.

vi editor query

I use vi quite often to edit files. Usually I need the file to appear on screen with line numbers. For this I do set nu in edit mode. What a drag! Can I automate this? Is there any way where vi will ...

KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

KornShell Printf - Padding a string

I m attempting to write a KornShell (ksh) function that uses printf to pad a string to a certain width. Examples: Call padSpaces Hello 10 Output Hello I currently have: padSpaces(){ ...

Redirection to a strange file descriptor no

I came across a working ksh script [interactive] today, where I saw the below statement. printf "Enter the release no. : " >&5 I wonder the use of >&5 when the author could have as ...

热门标签