I am using Linux and I want to write a shell script that takes two directories and moves the second directory in the first one (so the second directory becomes a subdirectory of the first one) and all the files from the second directory become ".txt" extension. For exemple: dir2 contains:
file1 file2 dir3 file3.jmp After running ./shell_scrip dir1 dir2, I want dir1 to contain dir2 and dir2 would look like this:
file1.txt file2.txt dir3 file3.txt I tried to change the extensions but I got this error:
mv: cannot stat `file1`: No such file or directory using the following code:
#!/bin/sh for file in $2/*; do f=$(basename "$file") mv "$f" "${f}.txt" done
echoin front of themvcommand to see where you're going wrongdir1here? Is the script supposed to create a new directory and move the existingdir2into this newdir1?