hi
I am in lab : variables and I think I have done the required modification in the script but still it does not marks it as pass .
Can you please let me know what more modifications are still needed in this script ?
What is that I am not doing correctly ?
Question
Another script by the name backup-file.sh
is placed in your home directory at /home/bob
.
This script creates a backup of a file by creating a copy of the same file and apending _bkp
to it’s name. However it’s not working’. Please inspect and fix the problem with the script.
- info_outline Hint
Variable should be encapsulated in { }
. Change variable to ${file_name}_bkp
-
Tasks not completed!
-
Script is fixed
bob@caleston-lp10:~$ cat backup-file.sh
# This script creates a backup of a given file by creating a copy as bkp
# For example some-file is backed up as some-file_bkp
file_name="file_name"
cp $file_name ${file_name}_bkp
bob@caleston-lp10:~$
bob@caleston-lp10:~$ ls -al
total 76
drwxr-xr-x 1 bob bob 4096 Nov 23 16:45 .
drwxr-xr-x 1 root root 4096 Apr 14 2020 ..
drwxrwxr-x 2 bob bob 4096 Apr 27 2020 .aws
-rw------- 1 bob bob 2571 May 23 2020 .bash_history
-rw-r--r-- 1 bob bob 70 Nov 23 16:12 .bashrc
drwx------ 3 bob bob 4096 Apr 27 2020 .cache
drwx------ 3 bob bob 4096 Apr 21 2020 .gnupg
drwx------ 4 bob bob 4096 Apr 27 2020 .local
-rw-rw-r-- 8 bob bob 135 Apr 27 2020 .profile
drwx------ 2 bob bob 4096 Apr 15 2020 .ssh-rw------- 8 bob bob 7838 Apr 27 2020 .viminfo
-rw-r--r-- 1 bob bob 75 Nov 23 16:12 .vimrc
-rwxrwxrwx 1 bob bob 182 Nov 23 16:45 backup-file.sh
-rwxr-xr-x 1 bob bob 273 Nov 23 16:27 create-and-launch-rocket
-rwxrwxrwx 1 bob bob 61 Nov 23 16:31 print-uptime.sh
-rwxrwxrwx 1 bob bob 140 Nov 23 16:29 print-welcome-message.sh
bob@caleston-lp10:~$bob@caleston-lp10:~$
bob@caleston-lp10:~$
bob@caleston-lp10:~$
with best regards
Pradeep Nehe