Posts

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...

User, UserID, UserGroup creation on Linux

1. How to Add a New User in Linux To add/create a new user, all you’ve to follow the command ‘ useradd ‘ or ‘ adduser ‘ with ‘username’. The ‘username’ is a user login name, that is used by user to login into the system. Only one user can be added and that username must be unique (different from other username already exists on the system). For example, to add a new user called ‘ tecmint ‘, use the following command. [root@tecmint ~]# useradd tecmint When we add a new user in Linux with ‘ useradd ‘ command it gets created in locked state and to unlock that user account, we need to set a password for that account with ‘ passwd ‘ command. [root@tecmint ~]# passwd tecmint Changing password for user tecmint. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully. Once a new user created, it’s entry automatically added to the ‘ /etc/passwd ‘ file. The file is used to store users information and the entry should be. tecmint:x:504:50...