Debian测试,bash ...
我正在尝试从现有程序中加载变量。
设置程序变量
xPROGS="$(echo -e "exiftool\nrsync\nxsel")"
尝试使用x(程序名称)创建变量
echo "$xPROGS" | while read z; do x$z="$(whereis -b "$z" | awk '{print $2}')" ; done
错误;
bash: xexiftool=/usr/bin/rsync: No such file or directory
bash: xrsync=/usr/bin/rsync: No such file or directory
bash: xxsel=/usr/bin/rsync: No such file or directory
这有效;
$ whereis -b rsync | awk '{print $2}'
我无法成功更改变量名。
有人可以帮忙。
$ cat t.sh
#!/bin/bash
progs=(exiftool rsync xsel)
for prog in "${progs[@]}"; do
read -r _ "x${prog}" _ <<< "$(whereis -b "${prog}")"
done
echo "exiftool: [${xexiftool}]"
echo "rsync: [${xrsync}]"
echo "xsel: [${xxsel}]"
$ ./t.sh
exiftool: []
rsync: [/usr/bin/rsync]
xsel: []
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句