[英]Shell script not taking arguments from input file
I have a input file which has user names and subject. 我有一个输入文件,其中包含用户名和主题。
input 输入
sk7865 /opt/apps/login
sk4888 /opt/apps/info
I am writing a shell script to take inputs from the above file and send a mail. 我正在编写一个shell脚本,以从上述文件中获取输入并发送邮件。
shell script 外壳脚本
#!/bin/bash
while read a b
echo echo ""$a"" | mail -s ""$b"" "$a"@example.com
done < input
In the above script the actual command I wanted to use is:- 在上面的脚本中,我想使用的实际命令是:
echo "hello world" | mail -s "a subject" someone@example.com
I want it to take arguments a,b at hello world , a subject to send the email to someone like I used it in the script. 我希望它在hello world上接受参数a,b,这是一个将电子邮件发送给我在脚本中使用过的人的主题 。 But it is not taking the arguments. 但这并没有引起争论。 I think it is something to do with double quotes. 我认为这与双引号有关。 Please provide me with proper script. 请提供适当的脚本给我。
You seem to be missing a do
after your while: 你似乎缺少一个do
你的一段时间后:
#!/bin/bash
while read -r a b
do
echo "$a" | mail -s "$b" "$a"@somewhere.com
done < input
Remember to always run shellcheck on your bash scripts before posting here. 请记住,在此处发布之前,始终对bash脚本运行shellcheck 。
Also, you had an echo echo
in there and double-double-quotes all over the place ""xyz""
. 另外,您在其中有一个echo echo
,并且在位置""xyz""
处使用了双引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.