in bash language, how can i define a list of paths of files?

Clash Royale CLAN TAG#URR8PPP
up vote
-2
down vote
favorite
In bash language, how can I define a list of paths?
I need something like below:
list_of_paths = ["$Home/MyDir/test.c", "$Home/YourDir/file.c"]
bash
add a comment |Â
up vote
-2
down vote
favorite
In bash language, how can I define a list of paths?
I need something like below:
list_of_paths = ["$Home/MyDir/test.c", "$Home/YourDir/file.c"]
bash
add a comment |Â
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
In bash language, how can I define a list of paths?
I need something like below:
list_of_paths = ["$Home/MyDir/test.c", "$Home/YourDir/file.c"]
bash
In bash language, how can I define a list of paths?
I need something like below:
list_of_paths = ["$Home/MyDir/test.c", "$Home/YourDir/file.c"]
bash
edited Jun 28 at 10:23
SivaPrasath
3,88611737
3,88611737
asked Jun 28 at 8:50
user297439
1
1
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
An array my be created in bash using
mypaths=( "/my/first/path" "/my/second/path" )
Elements of the array may also be assigned individually:
mypaths[0]="/my/first/path"
mypaths[1]="/my/second/path"
Note that there should be no spaces around the =.
This is described in the section called "Arrays" in the bash manual.
Using the array:
printf 'The 1st path is %sn' "$mypaths[0]"
printf 'The 2nd path is %sn' "$mypaths[1]"
for thepath in "$mypaths[@]"; do
# use "$thepath" here
done
Alternative for /bin/sh (will also work in bash and in a number of other sh-like shells):
set -- "/my/first/path" "/my/second/path"
printf 'The 1st path is %sn' "$1"
printf 'The 2nd path is %sn' "$2"
for thepath do
# use "$thepath" here
done
This uses the only array there is in a /bin/sh shell, which is the list of positional parameters ($1, $2, $3, etc., or collectively $@). This list usually contains the command line arguments for the script or shell function, but can be set explicitly in a script with set.
The loop at the end may also be written
for thepath in "$@"; do
# use "$thepath" here
done
Note that the quoting of every single variable expansion is significant.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
An array my be created in bash using
mypaths=( "/my/first/path" "/my/second/path" )
Elements of the array may also be assigned individually:
mypaths[0]="/my/first/path"
mypaths[1]="/my/second/path"
Note that there should be no spaces around the =.
This is described in the section called "Arrays" in the bash manual.
Using the array:
printf 'The 1st path is %sn' "$mypaths[0]"
printf 'The 2nd path is %sn' "$mypaths[1]"
for thepath in "$mypaths[@]"; do
# use "$thepath" here
done
Alternative for /bin/sh (will also work in bash and in a number of other sh-like shells):
set -- "/my/first/path" "/my/second/path"
printf 'The 1st path is %sn' "$1"
printf 'The 2nd path is %sn' "$2"
for thepath do
# use "$thepath" here
done
This uses the only array there is in a /bin/sh shell, which is the list of positional parameters ($1, $2, $3, etc., or collectively $@). This list usually contains the command line arguments for the script or shell function, but can be set explicitly in a script with set.
The loop at the end may also be written
for thepath in "$@"; do
# use "$thepath" here
done
Note that the quoting of every single variable expansion is significant.
add a comment |Â
up vote
2
down vote
An array my be created in bash using
mypaths=( "/my/first/path" "/my/second/path" )
Elements of the array may also be assigned individually:
mypaths[0]="/my/first/path"
mypaths[1]="/my/second/path"
Note that there should be no spaces around the =.
This is described in the section called "Arrays" in the bash manual.
Using the array:
printf 'The 1st path is %sn' "$mypaths[0]"
printf 'The 2nd path is %sn' "$mypaths[1]"
for thepath in "$mypaths[@]"; do
# use "$thepath" here
done
Alternative for /bin/sh (will also work in bash and in a number of other sh-like shells):
set -- "/my/first/path" "/my/second/path"
printf 'The 1st path is %sn' "$1"
printf 'The 2nd path is %sn' "$2"
for thepath do
# use "$thepath" here
done
This uses the only array there is in a /bin/sh shell, which is the list of positional parameters ($1, $2, $3, etc., or collectively $@). This list usually contains the command line arguments for the script or shell function, but can be set explicitly in a script with set.
The loop at the end may also be written
for thepath in "$@"; do
# use "$thepath" here
done
Note that the quoting of every single variable expansion is significant.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
An array my be created in bash using
mypaths=( "/my/first/path" "/my/second/path" )
Elements of the array may also be assigned individually:
mypaths[0]="/my/first/path"
mypaths[1]="/my/second/path"
Note that there should be no spaces around the =.
This is described in the section called "Arrays" in the bash manual.
Using the array:
printf 'The 1st path is %sn' "$mypaths[0]"
printf 'The 2nd path is %sn' "$mypaths[1]"
for thepath in "$mypaths[@]"; do
# use "$thepath" here
done
Alternative for /bin/sh (will also work in bash and in a number of other sh-like shells):
set -- "/my/first/path" "/my/second/path"
printf 'The 1st path is %sn' "$1"
printf 'The 2nd path is %sn' "$2"
for thepath do
# use "$thepath" here
done
This uses the only array there is in a /bin/sh shell, which is the list of positional parameters ($1, $2, $3, etc., or collectively $@). This list usually contains the command line arguments for the script or shell function, but can be set explicitly in a script with set.
The loop at the end may also be written
for thepath in "$@"; do
# use "$thepath" here
done
Note that the quoting of every single variable expansion is significant.
An array my be created in bash using
mypaths=( "/my/first/path" "/my/second/path" )
Elements of the array may also be assigned individually:
mypaths[0]="/my/first/path"
mypaths[1]="/my/second/path"
Note that there should be no spaces around the =.
This is described in the section called "Arrays" in the bash manual.
Using the array:
printf 'The 1st path is %sn' "$mypaths[0]"
printf 'The 2nd path is %sn' "$mypaths[1]"
for thepath in "$mypaths[@]"; do
# use "$thepath" here
done
Alternative for /bin/sh (will also work in bash and in a number of other sh-like shells):
set -- "/my/first/path" "/my/second/path"
printf 'The 1st path is %sn' "$1"
printf 'The 2nd path is %sn' "$2"
for thepath do
# use "$thepath" here
done
This uses the only array there is in a /bin/sh shell, which is the list of positional parameters ($1, $2, $3, etc., or collectively $@). This list usually contains the command line arguments for the script or shell function, but can be set explicitly in a script with set.
The loop at the end may also be written
for thepath in "$@"; do
# use "$thepath" here
done
Note that the quoting of every single variable expansion is significant.
edited Jun 28 at 13:43
answered Jun 28 at 8:57
Kusalananda
101k13199312
101k13199312
add a comment |Â
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%2f452381%2fin-bash-language-how-can-i-define-a-list-of-paths-of-files%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