Check if any argument matches using helper func
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have this:
ql_match_arg()
declare -a my_array=$1
for var in "$my_array[@]"; do
if [[ "$var" == "$2" ]]; then
return 0;
fi
done
ql_ls ()
local my_array=( "$@" ); ql_json=$(ql_match_arg my_array[@] '--json' && echo "yes")
ql_pid="$$" ql_json="$ql_json" ql_node_ls_all
what I am trying to do is create a helper function (ql_match_arg) which can be used by other functions to determine in any argument matches a given name. In this case, I want to find out if the --json flag is passed as any argument to ql_ls
.
The problem I have is that it's not looping over my_array - something is wrong with my code - either I am not passing the array to ql_match_arg
correctly, or something else is wrong.
bash shell-script
add a comment |Â
up vote
0
down vote
favorite
I have this:
ql_match_arg()
declare -a my_array=$1
for var in "$my_array[@]"; do
if [[ "$var" == "$2" ]]; then
return 0;
fi
done
ql_ls ()
local my_array=( "$@" ); ql_json=$(ql_match_arg my_array[@] '--json' && echo "yes")
ql_pid="$$" ql_json="$ql_json" ql_node_ls_all
what I am trying to do is create a helper function (ql_match_arg) which can be used by other functions to determine in any argument matches a given name. In this case, I want to find out if the --json flag is passed as any argument to ql_ls
.
The problem I have is that it's not looping over my_array - something is wrong with my code - either I am not passing the array to ql_match_arg
correctly, or something else is wrong.
bash shell-script
I think this basically has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have this:
ql_match_arg()
declare -a my_array=$1
for var in "$my_array[@]"; do
if [[ "$var" == "$2" ]]; then
return 0;
fi
done
ql_ls ()
local my_array=( "$@" ); ql_json=$(ql_match_arg my_array[@] '--json' && echo "yes")
ql_pid="$$" ql_json="$ql_json" ql_node_ls_all
what I am trying to do is create a helper function (ql_match_arg) which can be used by other functions to determine in any argument matches a given name. In this case, I want to find out if the --json flag is passed as any argument to ql_ls
.
The problem I have is that it's not looping over my_array - something is wrong with my code - either I am not passing the array to ql_match_arg
correctly, or something else is wrong.
bash shell-script
I have this:
ql_match_arg()
declare -a my_array=$1
for var in "$my_array[@]"; do
if [[ "$var" == "$2" ]]; then
return 0;
fi
done
ql_ls ()
local my_array=( "$@" ); ql_json=$(ql_match_arg my_array[@] '--json' && echo "yes")
ql_pid="$$" ql_json="$ql_json" ql_node_ls_all
what I am trying to do is create a helper function (ql_match_arg) which can be used by other functions to determine in any argument matches a given name. In this case, I want to find out if the --json flag is passed as any argument to ql_ls
.
The problem I have is that it's not looping over my_array - something is wrong with my code - either I am not passing the array to ql_match_arg
correctly, or something else is wrong.
bash shell-script
asked Apr 20 at 7:01
Alexander Mills
1,885929
1,885929
I think this basically has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
add a comment |Â
I think this basically has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
I think this basically has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
I think this basically has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
The problem I have is that it's not looping over my_array
With this:
declare -a my_array=$1
You are creating an array with just one value: $1
, the first argument passed to your script. So there is not much to loop over there.
If you want all arguments, try:
declare -a my_array=$@
Instead.
yeah thanks, I think this has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The problem I have is that it's not looping over my_array
With this:
declare -a my_array=$1
You are creating an array with just one value: $1
, the first argument passed to your script. So there is not much to loop over there.
If you want all arguments, try:
declare -a my_array=$@
Instead.
yeah thanks, I think this has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
add a comment |Â
up vote
1
down vote
The problem I have is that it's not looping over my_array
With this:
declare -a my_array=$1
You are creating an array with just one value: $1
, the first argument passed to your script. So there is not much to loop over there.
If you want all arguments, try:
declare -a my_array=$@
Instead.
yeah thanks, I think this has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The problem I have is that it's not looping over my_array
With this:
declare -a my_array=$1
You are creating an array with just one value: $1
, the first argument passed to your script. So there is not much to loop over there.
If you want all arguments, try:
declare -a my_array=$@
Instead.
The problem I have is that it's not looping over my_array
With this:
declare -a my_array=$1
You are creating an array with just one value: $1
, the first argument passed to your script. So there is not much to loop over there.
If you want all arguments, try:
declare -a my_array=$@
Instead.
answered Apr 20 at 7:07
maulinglawns
5,1881821
5,1881821
yeah thanks, I think this has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
add a comment |Â
yeah thanks, I think this has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
yeah thanks, I think this has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
yeah thanks, I think this has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09
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%2f438878%2fcheck-if-any-argument-matches-using-helper-func%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
I think this basically has the answer: askubuntu.com/questions/674333/â¦
â Alexander Mills
Apr 20 at 7:09