Check if any argument matches using helper func

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this question



















  • I think this basically has the answer: askubuntu.com/questions/674333/…
    – Alexander Mills
    Apr 20 at 7:09














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.







share|improve this question



















  • I think this basically has the answer: askubuntu.com/questions/674333/…
    – Alexander Mills
    Apr 20 at 7:09












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.







share|improve this question











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.









share|improve this question










share|improve this question




share|improve this question









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
















  • 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










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.






share|improve this answer





















  • yeah thanks, I think this has the answer: askubuntu.com/questions/674333/…
    – Alexander Mills
    Apr 20 at 7:09










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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






























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.






share|improve this answer





















  • yeah thanks, I think this has the answer: askubuntu.com/questions/674333/…
    – Alexander Mills
    Apr 20 at 7:09














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.






share|improve this answer





















  • yeah thanks, I think this has the answer: askubuntu.com/questions/674333/…
    – Alexander Mills
    Apr 20 at 7:09












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.






share|improve this answer














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.







share|improve this answer













share|improve this answer



share|improve this answer











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
















  • 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












 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?