[问题] Linux bash 语法问题

楼主: gecer (gecer)   2018-03-12 20:46:49
#!/bin/bash
if [$(cat ~/.bashrc |grep python3)=*'$HOME/python3/bin'*];then
sudo source ~/.bashrc
python3 -V
else
echo ""
echo ""
echo "You need to add \"export PATH=\$PATH:$HOME/python3/bin into
~/.bashrc\""
echo "Then execute \"source ~/.bashrc\""
fi
小弟预期用红字部分来看 bashrc内有无 python3 字眼 预期不是 空字串就是包含
'$HOME/python3/bin'
但是执行结果却出现
./python3_install2: line 2: [=*$HOME/python3/bin*]: No such file or directory
不太了解这个错误
作者: CP64 (( ̄▽ ̄#)﹏﹏)   2018-03-12 20:53:00
你两个方括号里面也要空格
作者: shiyeh (shiyeh)   2018-03-12 21:55:00
bash的空格不是空格
作者: hijkxyzuw (i,j,k) ×(x,y,z)   2018-03-12 22:31:00
if [ $(cat ~/.bashrc | grep python3) = *'...'* ]你可以直接 if fgrep '$HOME/python3/bin' ~/.bashrc还有 [ abc = a*c ] 是 false , [[ abc = a*c ]] true星号视为 glob 是双方括号才支援,还有星号建议要跳脱不然如果目录下有匹配的档名会被展开
作者: chang505 (眼线)   2018-03-12 23:26:00
不就跟你说没这档案了吗

Links booklink

Contact Us: admin [ a t ] ucptt.com