-
Notifications
You must be signed in to change notification settings - Fork 56
What is a bash script
A bash script is a simple file that contains ASCII text intended to be interpreted by the program bash, allowing you to run a logical sequence of commands by calling a simple line command instead of typing them one at a time in the shell.
The first line of a script should always tell the shell which program should interpret it:
#!/bin/bash
echo "Hello World, I am a 42 student!"
In this case, the script should be interpreted by /bin/bash and say Hello when it is invoked.
To invoke the script, you can type sh scriptname
or - in a better way - make it executable with a chmod
:
[shell prompt]$ chmod 755 scriptname
[shell prompt]$ ./scriptname
Add your commands one at a line in the script file and call external programs as you do in the shell. Bash has a lot of builtin functions and enables you to write some real applications with variables, conditions, loops, functions...
Info: 42FileChecker does not support the recommended way to execute a bash script by making it executable with a chmod
because any change made on a file of the project will automatically display a warning message at launch to tell the user that the local version differs with the remote one.
Introduction:
- What is Bash
- What is a bash script
- What is 42FileChecker
- Contributing to 42FileChecker
Bash syntax:
Bash tools:
- Builtin commands
- Awk
- Cat
- Grep
- Sed
Bash sample codes:
- Script auto-update (git tool)
- Create an interactive menu
- Animated spinner with a time out
- Static var test
- Check the basic rules of a makefile
- Forbidden functions test
- Memory leak test script
- Create a speed test