0

This is what I am trying

script1

var=10
sh -x script2 "$var"

script2

su - someuser << EOF
1
cd dir
echo "This is : $1 Error" >> somefile
2
2
0
exit
EOF

Everything in script2 is executing. When I am checking the file "somefile" the output is

This is :  Error

It is not showing the value of var

4

1 回答 1

0

它对我来说很好用:

cat s1
var=10
sh -x /tmp/s2 "$var"

cat s2
su - my_id << EOF
id
echo $1
EOF

./s1
+ su - my_id
+ 0<<
id
echo 10
my_id's Password: <<< su is prompting for my password
uid=222(my_id) gid=222(my_group) ...
10

因为你没有添加 #!/bin/xxxxx 我相信默认是执行 /bin/sh 或者 $SHELL 设置为。检查这两个是否符合您的预期。也许添加明确的 #!/bin/ksh (或 #!/bin/sh ...)以确保您获得了您想要/期望的外壳。

于 2013-05-14T11:45:51.997 回答