Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

pass parameters to bash script

# Run the script with the arguments as you would for
# every other command.
# Example: ./script.sh arg1 arg2 

#!/bin/sh
echo "argument1: $1"
echo "argument2: $2"

# Output: 
# argument1: arg1
# argument2: arg2
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

bash parse arguments

#!/bin/bash

SHORT=c:,d:,h
LONG=city1:,city2:,help
OPTS=$(getopt --alternative --name weather --options $SHORT --longoptions $LONG -- "$@")
Comment

bash params

read variable1
read variable2
...
Comment

PREVIOUS NEXT
Code Example
Shell :: ionic change app icon 
Shell :: bash date of file 
Shell :: lenovo touchpad not working ubuntu 
Shell :: Command to install tailwind plugin in vue 
Shell :: unix get epoch in miliseconds shell 
Shell :: how to see staged files in git 
Shell :: github api fetch 
Shell :: wsl2 vs virtualbox performance 
Shell :: pm2 show command 
Shell :: lumen with specific version 
Shell :: bash case statement 
Shell :: batch fork bomb 
Shell :: strapi run command 
Shell :: cp all files except one 
Shell :: kde 144 fps 
Shell :: add ssh github 
Shell :: git stash pop single file 
Shell :: list number of files in each folder linux 
Shell :: install package in docker 
Shell :: how to change hostname in kali linux 
Shell :: redis install ubuntu 20.04 
Shell :: undo most recent commit 
Shell :: start logstash 
Shell :: grep in windows 
Shell :: github desktop arch linux 
Shell :: git branch from current branch 
Shell :: echo venv/ .gitignore 
Shell :: git submodule add 
Shell :: ver particiones montadas linux 
Shell :: how to run code from github 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =