Questions tagged [brace-expansion]
A shell mechanism which is used to generate arbitrary strings.
156 questions
0
votes
0
answers
38
views
bash subshell execution behaves unexpectedly [duplicate]
I have a script which is supposed to fetch 2 URLs sequentially:
#!/bin/bash
wget_command='wget --restrict-file-names=unix https://www.example.com/{path1,path2}/'
$($wget_command)
echo $wget_command ...
1
vote
0
answers
34
views
zsh - autocomplete with braces in the middle of a directory
Suppose I have the following directory structure:
folder/
aaa/
f.txt
bbb/
f.txt
I want to compare the file f.txt as it is common to both directories. So in zsh I type this:
% diff folder/{...
9
votes
1
answer
671
views
Why does bash give the following result after brace expansion?
I am using linux and the following version of the bash:
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
When I type:
echo file{[1,2],3}.txt
I expect brace expansion to be done first, so:
...
2
votes
2
answers
211
views
Repeating zsh brace expansion values in zsh to download multiple files using wget2
I want to download all files named ${n}x${n} from a directory on a website with wget2 on zsh, where n is the same number value both times, with n from 1 to 6000.
I've found that specifying all the ...
0
votes
1
answer
133
views
Bash brace expansion doesn't work in an export statement
Consider the following example:
$ echo file_{a,b,c}
file_a file_b file_c # brace expansion worked :)
$ export VARIABLE=file_{a,b,c}
$ echo $VARIABLE
file_c # brace ...
0
votes
2
answers
380
views
Pass a variable that contains a comma as a -v option to qsub
After seeing the reactions on Stack Overflow on this question and an unfamiliarity with qsub, I believe thqt U&L is better suited for this question.
In qsub, we can pass environment variables (a ...
3
votes
3
answers
874
views
Brace expansion to run program multiple times with different arguments
I just learned about brace expansion and hoped I could make use of them to launch the same C++ program with different command line arguments.
My code is run like this from the terminal:
mpirun -n 1 ...
0
votes
1
answer
305
views
Bash - for range no longer works as wanted when one of the ends is a variable [duplicate]
#!/bin/bash
myfirstarray=(1 3 5 7 9 11)
for i in {2..4}
do
for j in {1..${myfirstarray[$((i-1))]}}
do
echo ${j}
done
done
In the code above the range of the ...
4
votes
1
answer
438
views
Why am I not able to use * with touch in path? [duplicate]
This is the output of tree:
[xyz@localhost Semester1]$ tree
.
├── Eng
├── IT
├── IT_workshop
├── LA
├── OS
├── OS_lab
├── Psy
├── Python
└── Python_lab
9 directories, 0 files
I want to create 3 ...
2
votes
1
answer
585
views
How to preserve parameter expansion passed to a function?
I have this function:
cyan=`tput setaf 6`
reset=`tput sgr0`
function Info()
{
echo "${cyan}$1${reset}"
}
And I use it in my other scripts as simple as Info some message.
However, when I ...
8
votes
2
answers
4k
views
Avoiding non-zero exit code when running `ls` using multiple patterns
Say I have two possible paths I want to list directories and files under on a Linux machine:
/some/path1/
/some/path2/
If I do the following in tcsh, I get 0 exit code, if at least one of path1 or ...
4
votes
3
answers
1k
views
Store expanded array in a variable using a brace expansion
I want to store node1 node2 node3 in a variable so that it may be used as an input to other scripts.
However, I want to do so by using brace expansion given by bash like so: node{1..3}
I tried to have ...
0
votes
1
answer
99
views
Is it possible to get the entire result of bash brace expansion between double quotes?
I would like to use Bash brace expansion and get the final result quoted between double quotes:
I managed to get that result only by using seq as follows:
echo '"'$(seq 1 5)'"';
output (...
2
votes
2
answers
76
views
brace expansion together with non permuting lists {txtfile,index}{1..3}.{txt,html} I want `{txtfile,index}` to correspond with `{txt,html}`
{txtfile,index}{1..3}.{txt,html}
I want {txtfile,index} to correspond with {txt,html}
to produce:
txtfile1.txt
txtfile2.txt
txtfile3.txt
index1.html
index2.html
index3.html
but this code will generate ...
2
votes
2
answers
137
views
bash brace expansion: is it possible to associate another list(s) with the initial list?
Example:
$ eval echo "{x,y,z}\ --opt\; "
x --opt; y --opt; z --opt;
Assume that the 2nd list is {1,2,3} and its length is equal to the length of the 1st (initial) list.
Questions:
How to ...