@sourabhtk37
How does arguments written in command line reaches the program magically in its form?
* - Not always shell.
We were here
EXECVE
#include <unistd.h>
int execve ( const char *filename, char *const argv[], char *const envp[]);
execve -> executes program
filename -> file to be executed/run
argv -> argument vector to be provided
envp -> list of name=value pair in environment
Alternative cousins: execvp, execl, execlp, execle, and execvp
Shell provided parsed argv to "run_execve"
Shell -> execve( "run_execve") -> execve("my_prog")
* - Not always shell.
We were here
Cmd-line parsing in Linux is done by the calling process/program before the new process is created.
In Windows it's the opposite.
Breaking Down Shell
$ sh haxxor.sh
$ chsh -s `which fish`
Breaking Down Shell
Breaking Down Shell
• Simple Commands: | The most common type of command. | |
• Pipelines: | Connecting the input and output of several commands. | |
• Lists: | How to execute commands sequentially. | |
• Compound Commands: | Shell commands for control flow. | |
• Coprocesses: | Two-way communication between commands. | |
• GNU Parallel: | Running commands in parallel. |
Compound commands
Breaking Down Shell
Brace expansion
Tilde expansion
Parameter and variable expansion
Command substitution
Arithmetic expansion
Word splitting
$ mkdir /dir/repo/{stage,develop,master}
# is expanded to
$ mkdir /dir/repo/stage
$ mkdir /dir/repo/develop
$ mkdir /dir/repo/master
$ ~
The value of $HOME
$ ~/foo
$HOME/foo
$ ~+/foo
$PWD/foo
$ array[0]=FishIsNice
$ echo ${array:0:4}
Fish
Breaking Down Shell
$ rm *.py *.c
# expands to
$ rm xyz.py doge.py exce.py prog.c more.c
Breaking Down Shell
$ yes "USE i3 and fish" > /dev/null
Breaking Down Shell
* - Not always shell.
We were here