简体   繁体   中英

How to pass an argument into a file in shell script?

Is it possible to pass an argument from a shell script and pass it to a file. This is what I am essentially trying to achieve:

My script:

#!/bin/bash -

input=$1
DIR=/home/user/

File=$DIR/test.txt

`cat $File` < $input


this is the test.txt:

select * from abc where date=$input;

I am pretty new to this stuff. please help if there's a correct approach to it.

You don't need to use cat but rather echo for this particular scenario.

echo "select * from abc where date='$input'" > test.txt

The double quotes will redirect and WRITE the echo along with the sentence expanded input variable to the text.txt variable.

If you want to append as opposed to write, use:

echo "select * from abc where date='$input'" >> test.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM