The command did not detect an error when using shell scripts

I am trying to execute the program as follows.

./chExt1.sh cpp test.CPP 

This should rename test.CPP to test.cpp , but I don’t even think this script runs at all.
I constantly get this " command not found error ".
the script is below:

 #!/bin/sh newExtension=$1; oldFile=$2; firstPart=`echo $oldFile | sed 's/\(.*\)\..*/\1/'` newName="$firstPart.$newExtension"; #echo $oldFile #echo $newName mv "$oldFile" "$newName" #echo "$oldFile" #echo "$firstPart" #echo "$newName" 
+4
source share
2 answers

Finally I solved the problem. Something went horribly wrong when I FTP'd a text file that contained a script, and then just passed it inside .sh to linux. I wrote from scratch in emacs and it cleared everything up.

+2
source

Based on your comment, do this in vi to remove additional control characters. I used to have this problem when editing files in gedit or when editing on Windows, and then when using on a Unix / Linux computer.

To remove ^M characters at the end of all lines in vi , use:

 :%s/^V^M//g 

^v is the Ctrl V character, and ^M is Ctrl M. When you type this, it will look like this:

 :%s/^M//g 

On UNIX, you can escape the control character by surpassing it with Ctrl V. :%s is the basic find and replace command in vi. He tells vi to replace the regular expression between the first and second slashes ( ^M ) with the text between the second and third slashes (in this case, there is nothing). g at the end directs vi to search and replace worldwide (all occurrences).

A source

+1
source

All Articles