0% found this document useful (0 votes)
110 views

Shell Scripting: by Karthik V

The document discusses Bash built-in variables like $#, $@, and $? that provide information about script parameters and exit status. It also shows examples of if/else conditional statements to test user input and check if a number is greater than 100. References are provided for further reading on differences between 0 and non-0 exit statuses in shell scripts.

Uploaded by

AravVivan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

Shell Scripting: by Karthik V

The document discusses Bash built-in variables like $#, $@, and $? that provide information about script parameters and exit status. It also shows examples of if/else conditional statements to test user input and check if a number is greater than 100. References are provided for further reading on differences between 0 and non-0 exit statuses in shell scripts.

Uploaded by

AravVivan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Shell Scripting

By Karthik V
$#, $@ & $?: Bash Built-in variables
file:test.sh
#! /bin/sh
echo '$#' $#
echo '$@' $@
echo '$?' $?

*If you run the above script as*

> ./test.sh 1 2 3

You get output:


$# 3
$@ 1 2 3
$? 0

*You passed 3 parameters to your script.*


$# = number of arguments. Answer is 3
$@ = what parameters were passed. Answer is 1 2 3
$? = was last command successful. Answer is 0 which means 'yes'
if else
##!/bin/bash

read -p "Enter a password" pass

if test "$pass" = "jerry"

then

echo "Password verified."

else

echo "Access denied."

fi
if Condition
#!/bin/bash

# Basic if statement

if [ $1 -gt 100 ]

then

echo Hey that\'s a large number.

fi
References:
http://unix.ittoolbox.com/groups/technical-functional/unixadmin-l/difference-betwee
n-0-and-in-unix-shell-scripts-1789925

You might also like