【发布时间】:2014-07-07 16:59:52
【问题描述】:
我想制作一个脚本来安装程序(ROS),我需要写这行:
sudo sh -c 'echo "TEXT VARIABLE TEXT" > systemFile' # to write in systemaFile I need sudo sh
如果 echo 只是固定文本,它可以工作。 如果 echo 是 text + variable 它不起作用。
我试过了:
read f1 < <(lsb_release -a | grep Code* | cut -f2) #codename is writted in variable $f1
echo $f1 # retruns "quantal" as I expected
sudo sh -c 'echo "TEXT $f1 TEXT" > systemFile' #f1 is empty, WHY?
那我还要在同一条指令sudo sh里面赋值变量,例如:
sudo sh -c ' 读取 f1 systemFile'
sh: 1: 语法错误:重定向意外
【问题讨论】:
-
& regd 为什么你的命令不起作用:变量扩展不会发生在单引号内。