Advertisement Upgrade to remove ads

Bash script:
sha bang

# !/bin/bash

bourne Script:

sha bang

#!/bin/sh

set permission to make bourn shell EXECUTABLE
someshell.sh

chmod 755 someshell.sh

Execute shell: someshell.sh

./someshell.sh

Create BOURN SCRIPT : 1.ask user his name,
2.say 'hello +(name)';
3.create a file with his name

var: NAME
file: NAME_file

#!/bin/sh
echo "What is your name?"
read NAME
echo "Hello ${NAME}"
touch "${NAME}_file"

BASH

check if command sucessfully executed.
===============
what value returns that it SUCESSFULLLY executed?

echo $?
=============
0 (i.e. zero)

bit bucket
==========
What is it?

/dev/null
================
toss the output away.

interpret this output line:

command: cmp file1 file2

Output: file1 file2 differ: char 18, line 2

??Where do the files differ??

line 2, 18 characters FROM THE START of the file

(NOT line 2, character #18 on line two)

Why is VARX = Susan?

Where:
Var1=Joe
Alternative is "Susan"

1. Write out the equation

VARX=${VAR1:+Susan}

a. Where:

person=${boy:-girl}

(variable "boy" is NOT defined! )
===================
a. write the command line for seeing the variable "person"

b. Show the result.
Variable "Person" = ????

c. is "girl" a variable or a literal string?
================
why?

a. echo $person

b. girl

c. literal string
=================
if "boy" is unassigned, and ":-", it defaults to the literal string.

a. Where:

person=${boy:-girl}

(boy predefined as "Tom" )
===================
a. write the command line for seeing the variable "person"

b. Show the result.
Variable "Person" = ????

c. is "girl" a variable or a literal string?
================
why?

a. echo $person

b. Tom

c. literal string
=================
If "boy" already has a value, then ":-" makes "person" take its vale.

-Suppose two respective possible variables (boy, girl) assigned to variable "person"

-var boy is NOT defined.

???---> Write a command line that sets makes "person" = "girl."

person=${boy:-girl}

-Suppose two respective possible variables (boy, girl) assigned to variable "person"

-already defined var "boy" ="Tom"

???---> Write a command line that sets var "person" = "girl".

person=${boy:+girl}

-Suppose two respective possible variables (boy, girl) assigned to variable "person"

-already defined var "boy" ="Tom"

???---> Write a command line that sets var "person" = "Tom".

person=${boy:-girl}

neither variable is defined.

sh-3.2$ VARX=${VAR3:+Susan}

????What will be the Value of "VARX"? Why?

Nothing.

"+" sign means that if VAR3 is defined, use Susan. If it's not defined, use VAR3.

write Bourn Script:

-loop all records of "for2.sh". -through: "hello", "1", all current dir files, "2", "goodbye"
-echo: "Looping ...i is set to [field] "

#!/bin/sh
for i in hello 1 * 2 goodbye
do
echo "Looping ... i is to $i"
done

======Example output========
sh-3.2$ ./for2.sh
Looping ... i is to hello
Looping ... i is to 1
Looping ... i is to 70a_sites.html
Looping ... i is to Desktop
Looping ... i is to Documents
Looping ... i is to Downloads
Looping ... i is to tom.sed
Looping ... i is to veggies
Looping ... i is to while.sh
Looping ... i is to work
Looping ... i is to work2
Looping ... i is to 2
Looping ... i is to goodbye

Please allow access to your computer’s microphone to use Voice Recording.

Having trouble? Click here for help.

We can’t access your microphone!

Click the icon above to update your browser permissions above and try again

Example:

Reload the page to try again!

Reload

Press Cmd-0 to reset your zoom

Press Ctrl-0 to reset your zoom

It looks like your browser might be zoomed in or out. Your browser needs to be zoomed to a normal size to record audio.

Please upgrade Flash or install Chrome
to use Voice Recording.

For more help, see our troubleshooting page.

Your microphone is muted

For help fixing this issue, see this FAQ.

Star this term

You can study starred terms together

NEW! Voice Recording

Create Set