I am new to Bash scripting. I have been trying to make a script that will swap the file names of the two files passed to it by the user.
Here's a picture of the two versions of my script so far
Here is the script in text format with
#! /bin/bash file1=$file1 file2=$file2 echo "write file name :" read file1 file2 if [[ $file1 = $file2 ]] then cp $file1 $file1 mv $file1 $file2 fi if [[ $file2 = $file1 ]] then mv $file2 $file1 fi
But my question is if I can make a script that let the user write down 2 filenames first, then the script will swap the 2 file names
The basic of swapping file names what I have read is this
cp $file1 temporaryfile mv $file1 $file2 mv $file2 temporyfile