Why does âcat fooâ not output foo, but âcat foo,barâ does?

Clash Royale CLAN TAG#URR8PPP
up vote
12
down vote
favorite
I was trying to concatenate text files in sub-folders and tried:
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1/book.txt > out$var
However this did not return anything. So, tried adding a non existing 'subfolder2'
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1,subfolder2/book.txt > out$var
And this time it did work out, concatenating the files successfully.
Why does this happens?
bash cat brace-expansion
add a comment |Â
up vote
12
down vote
favorite
I was trying to concatenate text files in sub-folders and tried:
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1/book.txt > out$var
However this did not return anything. So, tried adding a non existing 'subfolder2'
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1,subfolder2/book.txt > out$var
And this time it did work out, concatenating the files successfully.
Why does this happens?
bash cat brace-expansion
2
Useechoinstead ofcatto see what command line you got. (Or useset -xfor debugging.)
â Peter Cordes
May 20 at 6:46
add a comment |Â
up vote
12
down vote
favorite
up vote
12
down vote
favorite
I was trying to concatenate text files in sub-folders and tried:
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1/book.txt > out$var
However this did not return anything. So, tried adding a non existing 'subfolder2'
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1,subfolder2/book.txt > out$var
And this time it did work out, concatenating the files successfully.
Why does this happens?
bash cat brace-expansion
I was trying to concatenate text files in sub-folders and tried:
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1/book.txt > out$var
However this did not return anything. So, tried adding a non existing 'subfolder2'
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1,subfolder2/book.txt > out$var
And this time it did work out, concatenating the files successfully.
Why does this happens?
bash cat brace-expansion
edited May 20 at 3:00
Charles Duffy
734413
734413
asked May 19 at 6:39
CDPF
614
614
2
Useechoinstead ofcatto see what command line you got. (Or useset -xfor debugging.)
â Peter Cordes
May 20 at 6:46
add a comment |Â
2
Useechoinstead ofcatto see what command line you got. (Or useset -xfor debugging.)
â Peter Cordes
May 20 at 6:46
2
2
Use
echo instead of cat to see what command line you got. (Or use set -x for debugging.)â Peter Cordes
May 20 at 6:46
Use
echo instead of cat to see what command line you got. (Or use set -x for debugging.)â Peter Cordes
May 20 at 6:46
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
21
down vote
subfolder1 evaluates to subfolder1, since there are no alternatives. Use subfolder1 instead.
2
Note that it's different from incsh(where brace expansion comes from),tcshorfish.
â Stéphane Chazelas
May 19 at 9:50
add a comment |Â
up vote
20
down vote
By definition, brace expansion in GNU Bash requires either a sequence expression or a series of comma-separated values:
Patterns to be brace expanded take the form of an optional preamble, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript.
You can read the manual for details.
A few simple samples:
echo subfolder1
subfolder1
echo subfolder1,subfolder2
subfolder1 subfolder2
echo subfolder1
subfolder1
echo subfolder1..2
subfolder1 subfolder2
add a comment |Â
up vote
1
down vote
Braces will only expand if they have coma separated strings, for e.g. abc,def or range, for e.g. a..e specified between them.
In your case you can just write subfolder1 without enclosing it in braces as there is no need for that
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1/book.txt > out$var
Unfortunately,/path/a,/filenameexpands to the two strings/path/a/filenameand/path//filename, which may be unwanted.
â Kusalananda
May 19 at 17:02
thanks @Kusalananda for rectifying me, yes bash will provide a warning saing "ambiguous redirect"
â Neo_Returns
May 19 at 17:10
No, you getambiguous redirectif you try to redirect into a file given by an unquoted variable that has no value, e.g.echo 'hello' >$idontexist.
â Kusalananda
May 19 at 17:14
1
...or if the filename in the redirection gets expanded to multiple words. Like> *.txtwith multiple.txtfiles, or> $fileif$filecontains whitespace. But of course there's nothing ambiguous in givingcatmultiple arguments
â ilkkachu
May 20 at 8:33
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
21
down vote
subfolder1 evaluates to subfolder1, since there are no alternatives. Use subfolder1 instead.
2
Note that it's different from incsh(where brace expansion comes from),tcshorfish.
â Stéphane Chazelas
May 19 at 9:50
add a comment |Â
up vote
21
down vote
subfolder1 evaluates to subfolder1, since there are no alternatives. Use subfolder1 instead.
2
Note that it's different from incsh(where brace expansion comes from),tcshorfish.
â Stéphane Chazelas
May 19 at 9:50
add a comment |Â
up vote
21
down vote
up vote
21
down vote
subfolder1 evaluates to subfolder1, since there are no alternatives. Use subfolder1 instead.
subfolder1 evaluates to subfolder1, since there are no alternatives. Use subfolder1 instead.
edited May 19 at 9:34
David Foerster
915616
915616
answered May 19 at 6:45
Ignacio Vazquez-Abrams
32k66780
32k66780
2
Note that it's different from incsh(where brace expansion comes from),tcshorfish.
â Stéphane Chazelas
May 19 at 9:50
add a comment |Â
2
Note that it's different from incsh(where brace expansion comes from),tcshorfish.
â Stéphane Chazelas
May 19 at 9:50
2
2
Note that it's different from in
csh (where brace expansion comes from), tcsh or fish.â Stéphane Chazelas
May 19 at 9:50
Note that it's different from in
csh (where brace expansion comes from), tcsh or fish.â Stéphane Chazelas
May 19 at 9:50
add a comment |Â
up vote
20
down vote
By definition, brace expansion in GNU Bash requires either a sequence expression or a series of comma-separated values:
Patterns to be brace expanded take the form of an optional preamble, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript.
You can read the manual for details.
A few simple samples:
echo subfolder1
subfolder1
echo subfolder1,subfolder2
subfolder1 subfolder2
echo subfolder1
subfolder1
echo subfolder1..2
subfolder1 subfolder2
add a comment |Â
up vote
20
down vote
By definition, brace expansion in GNU Bash requires either a sequence expression or a series of comma-separated values:
Patterns to be brace expanded take the form of an optional preamble, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript.
You can read the manual for details.
A few simple samples:
echo subfolder1
subfolder1
echo subfolder1,subfolder2
subfolder1 subfolder2
echo subfolder1
subfolder1
echo subfolder1..2
subfolder1 subfolder2
add a comment |Â
up vote
20
down vote
up vote
20
down vote
By definition, brace expansion in GNU Bash requires either a sequence expression or a series of comma-separated values:
Patterns to be brace expanded take the form of an optional preamble, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript.
You can read the manual for details.
A few simple samples:
echo subfolder1
subfolder1
echo subfolder1,subfolder2
subfolder1 subfolder2
echo subfolder1
subfolder1
echo subfolder1..2
subfolder1 subfolder2
By definition, brace expansion in GNU Bash requires either a sequence expression or a series of comma-separated values:
Patterns to be brace expanded take the form of an optional preamble, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript.
You can read the manual for details.
A few simple samples:
echo subfolder1
subfolder1
echo subfolder1,subfolder2
subfolder1 subfolder2
echo subfolder1
subfolder1
echo subfolder1..2
subfolder1 subfolder2
edited May 19 at 9:44
ñÃÂsýù÷
14.7k82361
14.7k82361
answered May 19 at 6:56
Arthur Hess
3385
3385
add a comment |Â
add a comment |Â
up vote
1
down vote
Braces will only expand if they have coma separated strings, for e.g. abc,def or range, for e.g. a..e specified between them.
In your case you can just write subfolder1 without enclosing it in braces as there is no need for that
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1/book.txt > out$var
Unfortunately,/path/a,/filenameexpands to the two strings/path/a/filenameand/path//filename, which may be unwanted.
â Kusalananda
May 19 at 17:02
thanks @Kusalananda for rectifying me, yes bash will provide a warning saing "ambiguous redirect"
â Neo_Returns
May 19 at 17:10
No, you getambiguous redirectif you try to redirect into a file given by an unquoted variable that has no value, e.g.echo 'hello' >$idontexist.
â Kusalananda
May 19 at 17:14
1
...or if the filename in the redirection gets expanded to multiple words. Like> *.txtwith multiple.txtfiles, or> $fileif$filecontains whitespace. But of course there's nothing ambiguous in givingcatmultiple arguments
â ilkkachu
May 20 at 8:33
add a comment |Â
up vote
1
down vote
Braces will only expand if they have coma separated strings, for e.g. abc,def or range, for e.g. a..e specified between them.
In your case you can just write subfolder1 without enclosing it in braces as there is no need for that
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1/book.txt > out$var
Unfortunately,/path/a,/filenameexpands to the two strings/path/a/filenameand/path//filename, which may be unwanted.
â Kusalananda
May 19 at 17:02
thanks @Kusalananda for rectifying me, yes bash will provide a warning saing "ambiguous redirect"
â Neo_Returns
May 19 at 17:10
No, you getambiguous redirectif you try to redirect into a file given by an unquoted variable that has no value, e.g.echo 'hello' >$idontexist.
â Kusalananda
May 19 at 17:14
1
...or if the filename in the redirection gets expanded to multiple words. Like> *.txtwith multiple.txtfiles, or> $fileif$filecontains whitespace. But of course there's nothing ambiguous in givingcatmultiple arguments
â ilkkachu
May 20 at 8:33
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Braces will only expand if they have coma separated strings, for e.g. abc,def or range, for e.g. a..e specified between them.
In your case you can just write subfolder1 without enclosing it in braces as there is no need for that
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1/book.txt > out$var
Braces will only expand if they have coma separated strings, for e.g. abc,def or range, for e.g. a..e specified between them.
In your case you can just write subfolder1 without enclosing it in braces as there is no need for that
cat ./mainfolder1,mainfolder2,mainfolder3/subfolder1/book.txt > out$var
edited May 19 at 17:11
answered May 19 at 16:54
Neo_Returns
17311
17311
Unfortunately,/path/a,/filenameexpands to the two strings/path/a/filenameand/path//filename, which may be unwanted.
â Kusalananda
May 19 at 17:02
thanks @Kusalananda for rectifying me, yes bash will provide a warning saing "ambiguous redirect"
â Neo_Returns
May 19 at 17:10
No, you getambiguous redirectif you try to redirect into a file given by an unquoted variable that has no value, e.g.echo 'hello' >$idontexist.
â Kusalananda
May 19 at 17:14
1
...or if the filename in the redirection gets expanded to multiple words. Like> *.txtwith multiple.txtfiles, or> $fileif$filecontains whitespace. But of course there's nothing ambiguous in givingcatmultiple arguments
â ilkkachu
May 20 at 8:33
add a comment |Â
Unfortunately,/path/a,/filenameexpands to the two strings/path/a/filenameand/path//filename, which may be unwanted.
â Kusalananda
May 19 at 17:02
thanks @Kusalananda for rectifying me, yes bash will provide a warning saing "ambiguous redirect"
â Neo_Returns
May 19 at 17:10
No, you getambiguous redirectif you try to redirect into a file given by an unquoted variable that has no value, e.g.echo 'hello' >$idontexist.
â Kusalananda
May 19 at 17:14
1
...or if the filename in the redirection gets expanded to multiple words. Like> *.txtwith multiple.txtfiles, or> $fileif$filecontains whitespace. But of course there's nothing ambiguous in givingcatmultiple arguments
â ilkkachu
May 20 at 8:33
Unfortunately,
/path/a,/filename expands to the two strings /path/a/filename and /path//filename, which may be unwanted.â Kusalananda
May 19 at 17:02
Unfortunately,
/path/a,/filename expands to the two strings /path/a/filename and /path//filename, which may be unwanted.â Kusalananda
May 19 at 17:02
thanks @Kusalananda for rectifying me, yes bash will provide a warning saing "ambiguous redirect"
â Neo_Returns
May 19 at 17:10
thanks @Kusalananda for rectifying me, yes bash will provide a warning saing "ambiguous redirect"
â Neo_Returns
May 19 at 17:10
No, you get
ambiguous redirect if you try to redirect into a file given by an unquoted variable that has no value, e.g. echo 'hello' >$idontexist.â Kusalananda
May 19 at 17:14
No, you get
ambiguous redirect if you try to redirect into a file given by an unquoted variable that has no value, e.g. echo 'hello' >$idontexist.â Kusalananda
May 19 at 17:14
1
1
...or if the filename in the redirection gets expanded to multiple words. Like
> *.txt with multiple .txt files, or > $file if $file contains whitespace. But of course there's nothing ambiguous in giving cat multiple argumentsâ ilkkachu
May 20 at 8:33
...or if the filename in the redirection gets expanded to multiple words. Like
> *.txt with multiple .txt files, or > $file if $file contains whitespace. But of course there's nothing ambiguous in giving cat multiple argumentsâ ilkkachu
May 20 at 8:33
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444754%2fwhy-does-cat-foo-not-output-foo-but-cat-foo-bar-does%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Use
echoinstead ofcatto see what command line you got. (Or useset -xfor debugging.)â Peter Cordes
May 20 at 6:46