mardi 14 mai 2019

Is there a way to add a if-statement to my bash script?

I'd like to add if-statement but not sure. I don't want to mess up my code but also want to resolve the wget always showing "Downloading $file: DONE" even after adding -nc. I know it doesn't redownload yet it still runs on the command line.

I'd like to add these lines into my bash script or something and open to suggestions:

````do
````if [ ! "$i" = "a.txt" ] | [ "$i" = "a.txt" ]; then
````echo " DONE"
````echo -n "Downloading $file:"
````else
````echo " Skipped"
````echo -n "Already Downloaded $file:"
````fi
````done

This is my current bash script code:
````#!/bin/bash
````download()
````{
````local url=$1
````echo -n "    "
````wget -nc --progress=dot $url 2>&1 | \
````awk -v b='\b\b\b\b' '/%/{gsub(/./,""); printf "%s%4s",b,$2} END{print b}'
````echo " DONE"
````}

````for i in cat /home/pi/a.txt

````file="${i##*/}"
````echo -n "Downloading $file:"
````download "${i%/*}/$file"
````done

Would like it to say this when downloading: stay the same
echo " DONE"
echo -n "Downloading $file:"
else
Would like it to say this "Already Downloaded $file: Skipping" yet it still shows instead of what I see now "Downloading $file: DONE": add this
echo " Skipping"
echo -n "Already Downloaded $file:"

Aucun commentaire:

Enregistrer un commentaire