Posts

Showing posts from May, 2019

Bash Scripting Basics Part 3 | Read input and echo output

Bash Scripting Basics Part 3 | Read input and echo output #!/bin/bash # In this script we are getting input and set it will output varname_1=Ali echo "$varname_1: Hello, who am I talking to?" echo read varname echo echo "$varname_1: Nice to meet you, $varname" echo echo "$varname: How do you do?" echo echo "$varname_1: fine thank you, $varname" echo ########################################### # Ask the user for login details read -p 'Username: ' uservar read -sp 'Password: ' passvar echo echo Thankyou $uservar we now have your login details ########################################### # We can get multiple inputs from single user like below #!/bin/bash # Demonstrate how read actually works echo What cars do you like? read car1 car2 car3 echo Your first car was: $car1 echo Your second car was: $car2 echo Your third car was: $car3

Bash Scripting Basics Part 2 | Export variable to other script

#!/bin/bash # demonstrate variable scope 1. var1=ryan var2=mob # Let's verify their current value echo $0 :: var1 : $var1, var2 : $var2 echo export var1 ./exporting_variable_2.sh echo # Let's see what they are now echo $0 :: var1 : $var1, var2 : $var2 -------------------------------------------- # Second script in which we can export above mentioned variable #!/bin/bash # demonstrate variable scope 2 # Let's verify their current value echo New Var1 is $0 :: var1 : $var1, var2 : $var2 # Let's change their values var1=sam var2=john

Bash Scripting Basics Part 1

Bash Scripting Basics Part 1 #!/bin/bash # simple hello world bash script echo "Hello World!" ############################# cp $1 $2 # here we have copied argument1 to argument2, in arguments we can copy any file from src                 # to dst echo echo Details for $2 # here we can get details of second argument echo ls -lh $2 # in output we can have list of second argument directory or path echo echo Below is the ls for $1 # here we have list of first argument directory/path echo ls -lh $3 # here we have list of third argument directory/path ############################# # Other special variables   # echo Name of the script is: $0 echo echo $# - How many arguments were passed to the Bash script. echo echo $@ - All the arguments supplied to the Bash script. echo echo $? - The exit status of the most recently run process. echo echo $$ - The process ID of the current script. echo echo $USER - The u...