Do you need bash?
If you use the command line to do stuff, bash is just indispensable. In fact, being good on the command line requires bash or some other shell familiarity. Also, learning Bash is great for understanding how Unix and some of the core stuff really works — and how far we’ve come with tools like Python.
What do you need to execute a script?
Steps to write and execute a script
- Open the terminal. Go to the directory where you want to create your script.
- Create a file with . sh extension.
- Write the script in the file using an editor.
- Make the script executable with command chmod +x .
- Run the script using ./.
Why does the shell run in the current directory?
If the current directory is in PATH, the shell will try to execute the sl program in that directory (since there is no other sl program). That sl program might be malicious. It works with ./ because POSIX specifies that a command name that contain a / will be used as a filename directly, suppressing a search in $PATH.
Why do I need to type `./ ` before executing a program in..?
Then running the command in the shell would invoke your app instead of the built-in command. This would be a security concern if nothing else. By requiring ./ to be used in front, the shell knows that you want to execute the application with the given name and not a built-in command with that name.
Why do we use “./ ” to execute a file in Linux?
You need to tell the shell where a.out is – it it’s in the current directory (.) then the path is ./a.out. If you’re asking why it’s called “a.out”, that’s just the default output file name for gcc. You can change it with the -o command line arg.
Why is the current directory not in the path?
By default, the current directory is not in the path because it’s considered a security risk. See Why is . not in the path by default? on Superuser for why. It’s possible to add the current directory to your PATH, but for the reasons given in the linked question, I would not recommend it.