Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

shell script get arguments

$ myscript.sh first_arg second_arg

# myscript.sh
#!/bin/bash
echo $1 # output: first_arg
echo $2 # output: second_arg
Comment

linux shell parameter

# bash arguments cheatsheet
$1, $2, ... -> are the positional parameters.
"$@"        -> is an array-like construct of all positional parameters, {$1, $2, $3 ...}.
"$*"        -> is the IFS expansion of all positional parameters, $1 $2 $3 ....
$#          -> is the number of positional parameters.
$-          -> current options set for the shell.
$$          -> pid of the current shell (not subshell).
$_          -> most recent parameter (or the abs path of the command to start the current shell immediately after startup).
$IFS        -> is the (input) field separator.
$?          -> is the most recent foreground pipeline exit status.
$!          -> is the PID of the most recent background command.
$0          -> is the name of the shell or shell script.
Comment

command line argument bash

bash yourscript.sh file1 file2

yourscript.sh
inside script 

#!/bin/bash
a=$1     # = to file1
b=$2     # = file2
echo $1
echo $2
Comment

PREVIOUS NEXT
Code Example
Shell :: bash for i in range 
Shell :: bash function arguments 
Shell :: docker-compose command multiple 
Shell :: installer lamp ubuntui 
Shell :: how to revert a git stash 
Shell :: linux change owner 
Shell :: bash sed with variable 
Shell :: wsl settings 
Shell :: conda command not found 
Shell :: genymotion install ubuntu 
Shell :: command not found 
Shell :: linux script to clean up log files 
Shell :: grep binary files 
Shell :: rsync exclude 
Shell :: configure static ip address ubuntu server 20.04 
Shell :: download kubectl for windows 
Shell :: gatsby transformer remark 
Shell :: bash read file content 
Shell :: send post request webhook bash scipt 
Shell :: git move head to specific branch 
Shell :: fedora linux 
Shell :: git merge branch without merge ocmmit 
Shell :: sudo windows 
Shell :: how to convert dos to unix in shell 
Shell :: push docker image to docker hub 
Shell :: docker logs path var logs 
Shell :: ubuntu run a shell script 
Shell :: linux terminal show processes 
Shell :: powershell output array as table 
Shell :: nano go to line 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =