Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

how to create a bash script

#!/bin/bash

echo "Hello, world!"
Comment

bash make script

use below script to easilly create scripts with different types that are automaticaly set to executable

#!/bin/bash

version="1.0"

function help-text (){
	echo "-v : Show version"
	echo "-t : Type of script you want to create (bash/python3/...) defaults to bash"
	echo "-h : Show help text"
	exit 0;
}

args=("$@") 
ELEMENTS=${#args[@]}

if [[ $1 = "-h" ]]; then
	help-tekst
fi

for (( i = 0; i < $ELEMENTS; i++ )); do
	case ${args[${i}]} in
		"-"* )
			argument=${args[${i}]}
			for (( j=1; j<${#argument}; j++ )); do
			  	case "${argument:$j:1}" in
			  		"v"  )
						echo "Version: $version"
						;;
					"t"  )
						fileType=${args[${i}+1]}
						i=$i+1
						;;
					"h"  )
						help-text;
						exit 0;
						;;
					*	 )
						echo "-${argument:$j:1}" "invalid command, use -h for more info"
						;;
				esac
			done
			;;
		*	 )
			fileName=${args[${i}]};
			;;
	esac
done

if [[ -z "$fileName" ]]; then
	echo "No fileName was provided"
else
	if [[ -z "$fileType" ]]; then
		printf "#!/bin/bash
" > $fileName;
		chmod +x $fileName;
	else
		printf "#!/bin/$fileType
" > $fileName;
		chmod +x $fileName;
	fi
fi
Comment

bash script creation

echo '#!bin/bash' > filename 
# works with and without extention, if you want extention do filename.sh
chmod +x filename
Comment

example bash script

ipconfig /all
ping google.com
tracert google.com
PAUSE
Comment

create a bash script

#!/bin/sh
python /path/to/trc-image-titler.py -o /path/to/output
Comment

PREVIOUS NEXT
Code Example
Shell :: command stop emulator android studio 
Shell :: Bitwarden docker-compose 
Shell :: trojitá ubuntu 
Shell :: git remove user password 
Shell :: bash how to list all variables 
Shell :: how to save a file in emacs 
Shell :: where is my .git config mac 
Shell :: instal .deb ubuntu 
Shell :: cannot import urlencode from werkzeug 
Shell :: command to find the count of only words in a file in linux 
Shell :: Exception: Error running pod install flutter on iod 
Shell :: vscode running scripts is disabled on this system 
Shell :: bash remove newline from string 
Shell :: install openssh server linux 
Shell :: bluetooth headphone not working linux mint 
Shell :: git delete tag 
Shell :: discord update ubuntu 
Shell :: install ant design in react 
Shell :: clean up untagged docker images 
Shell :: git find files with conflicts, list files with conflict 
Shell :: terminal unzip 
Shell :: java.lang.IllegalStateException: Dex archives: setting .DEX extension only for .CLASS files 
Shell :: git mainstages 
Shell :: microstack no internet connection 
Shell :: unexpected MongoDBDriverExceptionConnectionException thrown from a caster: Server reports wire version 5, but this version of libmongoc requires at least 6 (MongoDB 3.6)", 
Shell :: linux awk print last column 
Shell :: docker build no cache layer dockerfile --no-cache "docker-compose" context 
Shell :: bash how to remove rows if specific field is blank 
Shell :: origin branch still showing in vscode though deleted 
Shell :: bash return length of every nth row 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =