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

how to create a bash script

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 :: git remove directory 
Shell :: shell script or condition 
Shell :: get total installed List from ubuntu terminal 
Shell :: warning unprotected private key file ec2 
Shell :: bash switch case 
Shell :: ubuntu install composer 
Shell :: how to check if helm is installed 
Shell :: react native map install npm 
Shell :: install nodejs debian 10 
Shell :: kubectl for windows 
Shell :: install github cli 
Shell :: remove letter in string bash 
Shell :: check files that was changed in a particular git commit 
Shell :: asyncstorage community 
Shell :: install homebrew on linux 
Shell :: remove yarn 0.32+git 
Shell :: brave browser download for linux 
Shell :: rm directory not empty mac 
Shell :: how to uninstall a software in ubuntu 
Shell :: discord linux 
Shell :: scp upload 
Shell :: readme folder structure 
Shell :: convert cer to crt linux mint 
Shell :: how to install prettier globally on mac 
Shell :: dash bootstrap import 
Shell :: ubuntu terminal autocomplete not working 
Shell :: command to create or change a password for a user 
Shell :: node global install 
Shell :: install postman desktop ubuntu 
Shell :: store credential cache git 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =