I want to execute a file in bash without the .sh extension.
Example: I have file "abc.sh" which I can execute directly (as I have added #!/bin/bash as the first line) but I want the filename to be just "abc"
Executables should have no extension (strongly preferred) or a . sh extension. Libraries must have a . sh extension and should not be executable.
1] Execute Shell Script file using WSL And search for “Windows Features”, choose “Turn Windows features on or off”. Scroll to find WSL, check the box, and then install it. Once done, one has to reboot to finish installing the requested changes. Press Restart now.
What are the permissions on the file? To make it executable with doing something like ./abc.sh
it needs to have EXECUTABLE rights.
You can always do bash abc.sh
Linux permissions overview
Filename in Linux doesn't mean anything in terms of execution capabilities, you can call the file myfile.something.something
and it can still be executable. You can name it abc
but it has to have EXECUTABLE
rights for the user,group,other.
To add that permission you can do chmod +x <filename>
but you should look at the link above for a better understanding.
In Linux you use ./filename
too run a script. And you need execute permission:
chmod 755 filename
But you still need the "Shebang":
#!/bin/bash
From here I got this:
If you did not put the scripts directory in your PATH, and . (the current directory) is not in the PATH either, you can activate the script like this:
./script_name.sh
A script can also explicitly be executed by a given shell, but generally we only do this if we want to obtain special behavior, such as checking if the script works with another shell or printing traces for debugging:
rbash script_name.sh
sh script_name.sh
bash -x script_name.sh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With