David C. Rankin wrote:
Anders Johansson wrote:
On Wednesday 14 May 2008 18:48:17 David C. Rankin wrote:
Listmates,
I am trying to use a bash list to move a group of files and directories under a single directory. It works, but I get a bash error I want to eliminate. How do I do it right so I can eliminate the error? Here is the situation. I want to move the following files and directories except "server" under the "desktop" directory with a single command:
drwxr-xr-x 2 david skyline 4096 2007-12-16 10:43 calc/ drwxr-xr-x 2 david skyline 4096 2007-07-24 21:34 crypto/ drwxr-xr-x 2 david skyline 4096 2008-05-14 11:37 desktop/ -rwxrwx--- 1 david skyline 4619908 2007-12-08 05:37 jpgraph-2.3.tar.gz* -rw-r--r-- 1 david skyline 608608 2008-02-21 22:43 kdesudo-2.4.tar.gz -rw-r--r-- 1 david skyline 503468 2008-03-03 20:38 KeePassX-0.3.0.tar.gz -rw-r--r-- 1 david skyline 27754 2008-03-03 02:42 pblogan-0.0.6-1.tar.gz drwxr-xr-x 2 david skyline 4096 2008-05-14 11:37 server/ -rw-r--r-- 1 david skyline 3251965 2008-02-22 21:17 sim-0.9.4.3.tar.bz2 -rwxr--r-- 1 david skyline 1050048 2008-02-22 22:04 trix-0.93.tar.bz2* -rw-r--r-- 1 david skyline 266574 2008-04-01 21:45 xca-0.6.4.tar.gz
I used this command line:
[11:38 nirvana/home/samba/computer/linux/apps] # mv { c* k* K* p* sim-0.9.4.3.tar.bz2 trix-0.93.tar.bz2 xca-0.6.4.tar.gz } desktop/
It all worked, but I got this error:
mv: cannot stat `{': No such file or directory mv: cannot stat `}': No such file or directory
Which makes sense because I didn't want the braces as directories only as list enclosures. How do I do it so I can eliminate the brace error?
What exactly is a "bash list"?
mv can handle multiple files, as long as the last parameter is a directory to be used as destination, so you don't need anything fancy from bash here. Just do
mv c* k* K* p* sim-0.9.4.3.tar.bz2 trix-0.93.tar.bz2 xca-0.6.4.tar.gz desktop/
and it will work.
I'm not sure at all where you found the idea of a bash "list" though. The bracket notation in bash normally means that you want to execute commands in the current shell (as opposed to the () notation, which means bash should launch a subshell for the commands).
Maybe you were confused by the notation
{ list; }
in the bash man page, but that just means it should be a list of commands to be executed (the basic idea is that you're interested in the whole as a group, so if one command fails, it should go on to the next command after the closing bracket)
Anders
Thanks to all that replied. Where I got the "bash list" from was the mkdir -p that used a similar "list" to create multiple sub directories in one command like:
mkdir -pv Documents/{accounting,research/{legal,factual},reference}
23:02 trinity~/tmp> mkdir -pv Documents/{accounting,research/{legal,factual},reference} mkdir: created directory `Documents' mkdir: created directory `Documents/accounting' mkdir: created directory `Documents/research' mkdir: created directory `Documents/research/legal' mkdir: created directory `Documents/research/factual' mkdir: created directory `Documents/reference'
It came from one of the bash tips&tricks sites I ran across. I'll admit, I couldn't find a reference to it in either man bash or the info doc.
Ah...that's under file-globbing, at least that's the section it was listed under in the AT&T Bourne Shell (sh) man page. Anything having to do with abbreviating file names on the command line, to be expanded by the shell is known as globbing. [By which I do *NOT* mean the use of a shell $VARIABLE] -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org