[opensuse] bash { list } question
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? -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Wednesday 14 May 2008 09:48, 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:
...
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's not entirely clear what you want, but if it's the argument synthesizing syntax, you're using it incorrectly. Try this: % echo left-{mid1,mid2,mid3}-right left-mid1-right left-mid2-right left-mid3-right If you're looking for the block construct, it must surround whole commands, not arguments: % { echo 1; echo 2; echo 3; } 1 2 3 (Note that the final semicolon is required unless you put the close brace on a new line.) If you're using the older globs, it would be more like this: % ls [ckKp]*
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?
"List enclosures?" BASH array variables are established like this: % listVar=( element1 element2 element3 ) % echo "${listVar[@]}" element1 element2 element3
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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. -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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
On Thu, 15 May 2008, David C. Rankin wrote:-
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.
You'll find an explanation under the section "Brace Expansion" of the bash man page. If you're using KDE, open Konqueror and type the following into the address bar: man://1/bash then you can use "find" to locate the various parts quickly. Regards, David Bolt -- Team Acorn: http://www.distributed.net/ OGR-P2 @ ~100Mnodes RC5-72 @ ~15Mkeys SUSE 10.1 32bit | openSUSE 10.2 32bit | openSUSE 10.3 32bit | openSUSE 11.0b1 SUSE 10.1 64bit | openSUSE 10.2 64bit | openSUSE 10.3 64bit RISC OS 3.6 | TOS 4.02 | openSUSE 10.3 PPC | RISC OS 3.11 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 15 May 2008 21:03, David C. Rankin wrote:
...
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}
The two key differences are the absence of white-space inside the curly-brace construct and the use of commas to separate the elements within.
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.
View the BASH man page and search for "Brace expansion". There's a whole section (seven paragraphs). CS Theory Section: Replace the braces with parentheses and the commas with vertical bars and you have a regular expression that will match all and only those strings that the brace expression generates.
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Wed, 14 May 2008, David C. Rankin wrote:-
[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?
You're adding spaces between the items in the list, instead of using commas. To do what you wanted, you should have used: 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 even that could be reduced to: mv {c,k,K,p}* {sim-0.9.4.3,trix-0.93}.tar.bz2 xca-0.6.4.tar.gz desktop/ Both of which would expand to the command that you actually executed: mv c* k* K* p* sim-0.9.4.3.tar.bz2 trix-0.93.tar.bz2 xca-0.6.4.tar.gz desktop/ But without the curly braces. Regards, David Bolt -- Team Acorn: http://www.distributed.net/ OGR-P2 @ ~100Mnodes RC5-72 @ ~15Mkeys SUSE 10.1 32bit | openSUSE 10.2 32bit | openSUSE 10.3 32bit | openSUSE 11.0b1 SUSE 10.1 64bit | openSUSE 10.2 64bit | openSUSE 10.3 64bit RISC OS 3.6 | TOS 4.02 | openSUSE 10.3 PPC | RISC OS 3.11 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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/
list in this case means list of commands.
It all worked, but I got this error:
mv: cannot stat `{': No such file or directory mv: cannot stat `}': No such file or directory
try this command line instead: # mv c* k* K* p* sim-0.9.4.3.tar.bz2 trix-0.93.tar.bz2 xca-0.6.4.tar.gz desktop/
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?
Don't use them, that's not what they're for.
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (5)
-
Anders Johansson
-
David Bolt
-
David C. Rankin
-
Randall R Schulz
-
Sam Clemens