When I'm Trying to Execute Bashscript but can't Started
When I'm Trying to Execute Bashscript but can't Started |
When I'm Trying to Execute Bashscript but can't Start - a little story about the experience of building scripts with bash on Linux, maybe you have experienced the same thing when creating scripts using Notepad ++ or others, then you import them into Linux and run them, it doesn't work properly.
Issue
When running a bash script created using Windows and executed on a Linux OS, the following error output occurs.
-bash: ./test_backup.sh: /bin/bash^M: bad interpreter: No such file or directory
Case
Below is an image containing a script that I created and edited using Notepad.
create bash on Notepad ++ |
Fortunately, there is a very helpful standard output.
bad interpreter |
-bash: ./test_backup.sh: /bin/bash^M: bad interpreter: No such file or directory
Maybe because the characters in notepad ++ that I use don't work in Linux itself, causing the script to not run.
Solving
This is because Windows uses '/r/n' while Linux only uses '/n', which causes scripts created in the Windows operating system using Notepad++ and run in the Linux operating system to not function as intended, resulting in error outputs.
To fix this is very easy to run the command below :
# sed -i -e 's/\r$//' "your_bashscript.sh // For your case # sed -i -e 's/\r$//' test_backup.sh // my case
And you have to believe in magic, rerun your bashscript, and see what happens. try running your bash script again, and I ask for help praying first
Trying
Please try again after you have done the solving as mentioned above, so that you will be more aware of the results after making changes to the script by adding characters with the 'sed' command and adjusted options.
To run it, use the command ./ as shown below, make sure you are already in the path where the .sh file is located.
# ./test_backup.sh
Success hit bash script |
Closing statement
The article recounts a personal experience with encountering difficulties executing a Bash script on Linux after creating and editing it using Notepad++. The issue arises from the characters used in Notepad++ not being compatible with Linux, leading to the script failing to run properly.
However, the problem is easily resolved by using the sed command to remove the incompatible characters from the script. After doing so, the script runs successfully. The author concludes by sharing this solution and expressing hope that the article proves useful to readers.
Maybe that's all I can share with you guys, hopefully this article will be useful.
Thank You
Post a Comment for "When I'm Trying to Execute Bashscript but can't Started"
Post a Comment