Answer the question
In order to leave comments, you need to log in
[[+content_image]]
Why does if work like this in bash?
Good afternoon, there is such a simple script
NAME=$1
FORMAT=$2
INPUT_FILE=$3
DATA=$(date "+%Y-%m-%d")
ARHIVE_NAME=$(echo $NAME-$DATA.$FORMAT)
# tar or zip
if [[ "$FORMAT"=="tar" ]]; then
tar cf $ARHIVE_NAME $INPUT_FILE
echo "tar successfully"
elif [[ "$FORMAT"=="zip" ]]; then
zip $ARHIVE_NAME $INPUT_FILE
echo "zip successfully"
fi
~/Documents/Bash/bash-scripting
❯ bash creating-archives.sh isamarskiy zip file
tar successfully
~/Documents/Bash/bash-scripting
❯ bash creating-archives.sh isamarskiy tar file
tar successfully
❯ ls
creating-archives.sh file isamarskiy-2020-04-18.tar isamarskiy-2020-04-18.zip
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question