You need to write a script that displays the user name, home directory. Adds all home directory files to the archive. If an archive with the same name already exists, then print a warning.

#! /bin/bash who=$(whoami); echo "Пользователь системы: $who"; echo "Домашний каталог: $HOME"; first=$(ls *back_up_name_$(date +%A).zip*); second="back_up_name_$(date +%A).zip"; if [ $first -eq $second ]; then read -p "Переписать файл? (1/0)" choise; if [$choise -eq 1]; then zip back_up_name_$(date +%A).zip else exit 0 fi else zip back_up_name_$(date +%A).zip; fi exit 0; 

It does not work correctly, I can not figure out why.

  • This is a variable idea. Found such a line in some manual. - Simon
  • And what exactly is wrong? - Flowneee
  • one
    checking the existence of a file is easier if [ -f имя_файла ] - Mike

1 answer 1

Maybe the case is the absence of spaces in square brackets?

 if [ $choise -eq 1 ]; then 
  • Yes thank you. if [-f filename] - this also helped make life easier. - Simon