shell经过wget
本帖最后由 逸笙 于 2019-3-24 16:16 编辑LOC大佬多。
[*]while [ -z "${user}" ]
[*]do
[*] read -p "Input your account:" user
[*]done
[*]while [ -z "${pwd}" ]
[*]do
[*] read -p "Input your password:" pwd
[*]done复制代码
简单的几句,如果本地运行不会有问题,wget到本地后再bash也没有问题。
但如果打算wget -O- xxx.com/aaa.sh | bash,就有问题了,
首先是没有停下来输入user跟pwd,
然后提示:line 11: syntax error near unexpected token `do'
这个11行是第2个do,我echo user出来,它居然是"这样三行,百度了半天,好像while是自己的小环境,给|一下后就会出错。
那怎么实现呢,我想用户不输入user就继续提示输入,然后还想可以直接wget -O- 来 | bash这样。
==================
read -p "Input your password:" pwd < /dev/tty
感谢dupit8 本帖最后由 dupit8 于 2019-3-24 16:01 编辑
当然出错了,因为 read 的缺省就是标准输入,而你已经把标准输入重定向到wget去了。
你可以把命令行写成
bash <(wget -O http://xxx.com/xx.sh)
而不是
wget -O - http://xxx.com/xx.sh|bash
或者
read -p "Input your password:" pwd < /dev/tty 小白不懂,顶一下 惨案 wget xxx.com/aaa.sh && bash aaa.sh && rm aaa.sh
看不懂为啥要用管道, 为了一行写几个命令? 那用&&也行吧
页:
[1]