[英]How to pass an argument into a file in shell script?
是否可以从 shell 脚本传递参数并将其传递给文件。 这就是我本质上想要实现的目标:
我的脚本:
#!/bin/bash -
input=$1
DIR=/home/user/
File=$DIR/test.txt
`cat $File` < $input
这是 test.txt:
select * from abc where date=$input;
我对这些东西很陌生。 如果有正确的方法,请提供帮助。
对于这种特定情况,您不需要使用 cat 而是使用 echo 。
echo "select * from abc where date='$input'" > test.txt
双引号将重定向并将回声连同句子扩展输入变量一起写入 text.txt 变量。
如果要 append 而不是写,请使用:
echo "select * from abc where date='$input'" >> test.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.