Add braces to a command

wallis

New Member
Joined
May 15, 2024
Messages
4
Reaction score
1
Credits
52
I want to automate a scp command like the following:
scp [email protected]:/home/pi/remote/\{aaainremote,bbbinremote,cccinremote\} /home/pi/local
The above command works as expected when entered in a terminal.



The following is a condensed version of my bash script named cwmscp:
The variables are named as arguments in the full script, but simplified here as shown.
filename1=“aaainremote”
filename2=“bbbinremote”
file names=“cccinremote”
ipaddress=“192.168.1.100”
source=“/home/pi/remote/“
destination=“/homepi/local”
scp pi@$ipaddress:$source\{filename1,filename2,filename3\} $destination

When I execute the bash script, I get the password prompt for the remote system and I enter the password.
The first file, aaainremote is copied, but not the bbbinremote or cccinremote.
I can change the order of the three file names and only the first file named is copied

I get the the following output:

[email protected]’s password: (I enter the password)
aaainremote. 100% 4. 6.9KB/s. 00:00
scp: /home/pi/remote: not a regular file
scp: /home/pi/remote: not a regular file

The three files are identical test files with different names:
Only the first file named in the scp command gets copied.


I can manually type the following in a terminal session and all three files get copied as expected:
scp [email protected]:/home/pi/remote/\{aaainremote,bbbinremote,cccinremote\} /home/pi/local
 


my understanding of the command syntax is that you can specify only one file not 2 or more.
scp pi@$ipaddress:$source\{filename1,filename2,filename3\} $destination
Local file
names can be made explicit using absolute or relative pathnames
to avoid treating file names containing ‘:’ as host specifiers.

Your syntax is contradictory to the quoted docs:
 
my understanding of the command syntax is that you can specify only one file not 2 or more.

As @wallis said, his code works as a terminal command. So, I would be asking the same question. Why not in a bash, if it works in terminal? It doesn't really make sense to me. And as I'm a newb, that's to be expected.
 
I got the syntax I used from some documentation, so I will do some more reading, but as @CaffeineAddict said, why does it work in a terminal command. I tried the scp in a terminal prompt again as follows and all three files are copied.
The terminal command I used that copies all 3 files is:
scp [email protected]:/home/pi/remote/\{aaainremote,bbbinremote,cccinremote\} /home/pi/local

I am new to bash scripting and would appreciate any help on why the scp command works from a terminal prompt and not when using variable names.

Thanks for all comments.
 
G'day @wallis and welcome to linux.org :)

I am moving this to Command Line where scripting inquiries are also handled.

Good luck

Chris Turner
wizardfromoz
 

Members online


Top