From 88e70d61f27a0f5bda0fb2e3dbf646c6859de19a Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Mon, 3 Jul 2017 13:34:32 -0700 Subject: [PATCH] Changed $1 $2 $3 etc to just $@ (#28) * Now using $@ for readability and maintainability --- movies/movies | 4 ++-- stocks/stocks | 2 +- taste/taste | 10 +++++----- weather/weather | 5 +++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/movies/movies b/movies/movies index 675b193..236a469 100755 --- a/movies/movies +++ b/movies/movies @@ -47,7 +47,7 @@ checkInternet() getMovieInfo() { apiKey=946f500a # try not to abuse this it is a key that came from the ruby-scripts repo I link to. - movie=$(echo $1 $2 $3 $4 $5 $6 $7 $8 $9 | tr " " + ) ## format the inputs to use for the api + movie=$(echo $@ | tr " " + ) ## format the inputs to use for the api export PYTHONIOENCODING=utf8 #necessary for python2 in some cases movieInfo=$(httpGet "http://www.omdbapi.com/?t=$movie&apikey=$apiKey") > /dev/null # query the server and get the JSON response checkResponse=$(echo $movieInfo | python2 -c "import sys, json; print json.load(sys.stdin)['Response']") @@ -167,6 +167,6 @@ elif [[ $1 == "update" ]];then elif [[ $1 == "help" ]];then usage else - getMovieInfo $1 $2 $3 $4 $5 $6 $7 $8 $9 || exit 1 ## exit if we return 1 (chances are movie was not found) + getMovieInfo $@ || exit 1 ## exit if we return 1 (chances are movie was not found) printMovieInfo ## print out the data fi diff --git a/stocks/stocks b/stocks/stocks index 84e96d1..3c82be1 100755 --- a/stocks/stocks +++ b/stocks/stocks @@ -183,7 +183,7 @@ elif [[ $# == "0" ]];then usage exit 0 else - getTicker $1 $2 $3 $4 $5 $6 $7 $8 $9 # the company name might have spaces so passing in all args allows for this + getTicker $@ # the company name might have spaces so passing in all args allows for this getStockInformation $symbol # based on the stock symbol exrapolated by the getTicker function get information on the stock printStockInformation # print this information out to the user in a human readable format exit 0 diff --git a/taste/taste b/taste/taste index 9ecab17..30bf8e5 100755 --- a/taste/taste +++ b/taste/taste @@ -91,7 +91,7 @@ update() getSimilar() { export PYTHONIOENCODING=utf8 #necessary for python2 in some cases - media=$( echo "$1 $2 $3 $4 $5 $6 $7 $8" | tr " " + ) + media=$( echo "$@" | tr " " + ) response=$(httpGet "https://tastedive.com/api/similar?q=$media&k=$apiKey&info=$info") ## Extrapolate the information by parsing the JSON nameOne=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Results'][0]['Name']" 2> /dev/null || { echo "Error: Did you search a valid item?"; return 1; } ) @@ -112,7 +112,7 @@ getSimilar() getInfo() { export PYTHONIOENCODING=utf8 #necessary for python2 in some cases - media=$( echo "$1 $2 $3 $4 $5 $6 $7 $8" | tr " " + ) + media=$( echo "$@" | tr " " + ) response=$(httpGet "https://tastedive.com/api/similar?q=$media&k=$apiKey&info=$info") name=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Name']") type=$(echo $response | python2 -c "import sys, json; print json.load(sys.stdin)['Similar']['Info'][0]['Type']") @@ -238,14 +238,14 @@ elif [[ $1 == "help" ]];then else if [[ $search == "0" ]];then if [[ $info == "0" ]];then - getSimilar $1 $2 $3 $4 $5 $6 $7 $8 || exit 1 ## exit if we return 1 (chances are movie was not found) + getSimilar $@ || exit 1 ## exit if we return 1 (chances are movie was not found) printResults else - getSimilar $2 $3 $4 $5 $6 $7 $8 $9 || exit 1 + getSimilar $@ || exit 1 printResults fi else - getInfo $2 $3 $4 $5 $6 $7 $8 $9 || exit 1 ## exit if we return 1 (chances are movie was not found) + getInfo ${@:2} || exit 1 ## exit if we return 1 (chances are movie was not found) printInfo fi fi diff --git a/weather/weather b/weather/weather index 43923a9..e6510b4 100755 --- a/weather/weather +++ b/weather/weather @@ -49,7 +49,8 @@ getIPWeather() getLocationWeather() { - httpGet $locale.wttr.in/$1+$2+$3+$4 + args=$(echo $@ | tr " " + ) + httpGet $locale.wttr.in/${args} } checkInternet() @@ -158,5 +159,5 @@ elif [[ $1 == "m" ]]; then elif [[ $1 == "i" ]]; then getIPWeather "?u" else - getLocationWeather $1 $2 $3 $4 + getLocationWeather $@ fi