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 arguments

# 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 :: github gist api 
Shell :: ubuntu uninstall composer 
Shell :: how to run multiple npm scripts parallel 
Shell :: yarn change version 
Shell :: grep count words 
Shell :: git new branch create 
Shell :: alertmanager reload config 
Shell :: ubuntu change /etc/resolv.conf 
Shell :: use output of pipe xargs 
Shell :: rename a branch alredy pushed 
Shell :: how uninstall composer 
Shell :: check os shell liunx cygwin darwin 
Shell :: search for a filetype extension PowerShell 
Shell :: npm install proxy 
Shell :: clone code -lr 
Shell :: react native navigation 
Shell :: how to kill running port in ubuntu 
Shell :: proxmox home assistant 
Shell :: bash home backup script linux 
Shell :: randomstring npm 
Shell :: change git repository commmand 
Shell :: mac docker-compose 
Shell :: tinymce yarn 
Shell :: django view sql behind migration 
Shell :: how to realse the lock in the linux in apt 
Shell :: how to compare files in terminal 
Shell :: installing whatsapp 
Shell :: task manager ubuntu 
Shell :: webpack/config/html 
Shell :: linux get oldest file in directory 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =