mirror of
https://github.com/alexanderepstein/Bash-Snippets
synced 2018-11-08 02:59:35 +01:00
Replacing bc everywhere, currency exchange trys to use bc still
This commit is contained in:
parent
a4cc7a509a
commit
d8980a0a9c
@ -167,7 +167,7 @@ getGithubRepoNames()
|
||||
for repo in $repoResponse; do ## go through each repo
|
||||
if [[ $source == "1" ]]; then ## if the user set the source flag
|
||||
if [[ ${forkResponse[$count]} == "false" ]]; then repoNames+=("$repo"); fi ## if they are the owner of the repository add it to the list of repoNames
|
||||
count=$(echo $count + 1 | bc) ## increment the counter
|
||||
count=$(( $count + 1 )) ## increment the counter
|
||||
else ## the user didnt set the source flag
|
||||
repoNames+=("$repo") ## add all repos in repoResponse to repoNames
|
||||
fi
|
||||
@ -264,7 +264,7 @@ if [[ $all == "0" ]]; then
|
||||
backupRepo || { echo "Error: couldnt backup $repoName to bitbucket"; exit 1; }
|
||||
exit 0
|
||||
else ## flags are set but arguments are also provided
|
||||
firstArg=$(echo $private + $tStamp + 1 | bc)
|
||||
firstArg=$(( $private + $tStamp + 1 ))
|
||||
getGitHubUserInfo || exit 1
|
||||
getBitbucketInfo || exit 1
|
||||
for i in "${@:$firstArg}"; do
|
||||
|
@ -166,7 +166,12 @@ convertCurrency()
|
||||
{
|
||||
exchangeTo=$(echo "$exchangeTo" | tr '[:upper:]' '[:lower:]')
|
||||
exchangeRate=$(httpGet "https://api.coinmarketcap.com/v1/ticker/$reqId/?convert=$exchangeTo" | grep -Eo "\"price_$exchangeTo\": \"[0-9 .]*" | sed s/"\"price_$exchangeTo\": \""//g) > /dev/null
|
||||
exchangeAmount=$(echo "$exchangeRate * $amount" | bc )
|
||||
if ! command -v bc; then
|
||||
exchangeRate=$(echo $exchangeRate | grep -Eo "[0-9]*" )
|
||||
exchangeAmount=$(( $exchangeRate * $amount ))
|
||||
else
|
||||
exchangeAmount=$( echo "$exchangeRate * $amount" | bc )
|
||||
fi
|
||||
exchangeTo=$(echo "$exchangeTo" | tr '[:lower:]' '[:upper:]')
|
||||
base=$(echo "$base" | tr '[:lower:]' '[:upper:]')
|
||||
|
||||
|
@ -137,7 +137,13 @@ checkInternet()
|
||||
convertCurrency()
|
||||
{
|
||||
exchangeRate=$(httpGet "http://api.fixer.io/latest?base=$base&symbols=$exchangeTo" | grep -Eo "[0-9]*[.][0-9]*") > /dev/null
|
||||
exchangeAmount=$(echo "$exchangeRate * $amount" | bc)
|
||||
if ! command -v bc; then
|
||||
exchangeRate=$(echo $exchangeRate | grep -Eo "[0-9]*" )
|
||||
exchangeAmount=$(( $exchangeRate * $amount ))
|
||||
else
|
||||
exchangeAmount=$( echo "$exchangeRate * $amount" | bc )
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
|
||||
=========================
|
||||
|
@ -97,7 +97,7 @@ removeTask()
|
||||
for task in $(cat ~/.todo/list.txt); do
|
||||
if [[ $count != $taskNumber ]]; then
|
||||
echo "$task" >> ~/.todo/temp.txt;fi
|
||||
count=$(echo $count + 1 | bc)
|
||||
count=$(( $count + 1 ))
|
||||
done
|
||||
rm -f ~/.todo/list.txt
|
||||
cp ~/.todo/temp.txt ~/.todo/list.txt
|
||||
@ -122,7 +122,7 @@ getTasks()
|
||||
for task in $(cat ~/.todo/list.txt); do
|
||||
if [ $count -lt 10 ]; then count="0$count"; fi
|
||||
echo "$count). $task" >> ~/.todo/getTemp.txt
|
||||
count=$(echo $count + 1 | bc)
|
||||
count=$(( $count + 1 ))
|
||||
done
|
||||
cat ~/.todo/getTemp.txt | column -t -s ";"
|
||||
rm -f ~/.todo/getTemp.txt
|
||||
|
Loading…
Reference in New Issue
Block a user