简体   繁体   中英

How to Preserve variable spacing in FTP command in BASH?

Hi here is what i am trying to do

string='quote site LRECL=4096 - quote site RECFM=VB'
echo $string | sed s/-/\\n/g

Output is:

quote site LRECL=4096 
quote site RECFM=VB

But when i try doing FTP as:

ftp_f=`ftp -vni $ADDRESS <<EOF > log_fil
user $USER $PASS
$string | sed s/-/\\n/g
bye
EOF`

It does not create newline here so it executes only one quote site command when I need to execute as many of them as there are in the string variable. I tried storing echo $string | sed s/-/\\\\n/g echo $string | sed s/-/\\\\n/g in a new variable to call it with quotes as "$string2" within FTP ,but FTP does not recognize it. Please tell me what to do ?

1) The problem may not need sed , first try this:

string="user $USER $PASS
quote site LRECL=4096
quote site RECFM=VB
bye
"

ftp_f=`echo "$string" | ftp -vni $ADDRESS > log_fil`

But if sed is needed, read on...

2) To store a multi-line command in a string that can be output to a pipe, try something like:

foo="{ echo hi ; echo ho ; }"
eval "$foo" | sed s/h/H/

...which outputs:

Hi
Ho

Be careful with eval , as it can run anything (ie terrible things like rm -f * ). If any user input is to be used in a string that goes to eval , parse and check it first.

Avoid variable names that are also command names. There's already a string command.

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