Bash Script

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What does special variable $# mean/do?

$# - Typically used in the function; this is the number of arguments supplied to a script Like a line that shows total number of parameters used. example for 2 "Total number of Parameters: $#" output can be "Total number of parameters:2"

What does special variable $0 mean/do?

$0 - The filename of the current script if filename is $./test.sh $0= ./test.sh

How does linix use Boolean values?

$? - This is will give Yes or no; yes being 0 and no being 1.

What does special variable $n mean/do?

$n - n is a positive decimal number corresponding to the position of an argument ( $1, is 1st, $2 is 2nd argument...) After executing the program you enter the arguments and it will get entered into the parameters.

Combining Conditions

&& = AND || OR ! = not

Which Operators are supported by Bourne Shell

+ - "\*" / % = == != `expr $a + $b` ^^typical way to write this Conditional Expressions should be into side Square braces example [ $a == $b ]

What Numeric conditions do you have?

-eq = Equal -ne = not Equal -It= less than -Le = less than or equal -gt = greater than -ge = greater than or equal

What does special variable $@ mean/do?

All arguments are individually double quoted. and if script receives two arguments, $@ means $1 $2. This will take entire list as and separates it into separate arguments.

What does special variable $* mean/do?

All the arguments are double quoted. If a script receives two arguments, $* is same as $1 $2 This takes all list as one argument with spaces between.

How do you alert the system that a shell script is being started/

By using a shebang construct #!/bin/bash

How do you use a if elif else fi statement

If [ ] then ["expression" elif [function] then "expression" elip [function] then.... else [function] "expression" fi

What is Shell?

Provides a interface with unix system, It gathers input from your and executes program based on it and displays the programs output

What is the difference between Telnet and SSH?

SSH offers more security of data when transferring between systems. While SSH data is encrypted, Telnet data is transferred in plain text (ASCII form) and Telnet is mostly used in a Private network

What is a Hard Link?

Simply an additional name for existing file on Linux. What command is used to create it. <ln file1 hlink1> How can you display hard links? use the ls-l the l is for long

what is a until loop?

Sometimes you need to do a command until something is true, you can use until loop a=0 while [ $a -it 10 ] do echo $a a=`expr $a +1` done

When executing a program

Start with Bash not with sh so Bash filename.sh

What strings conditions do you have?

String -Z =Empty -n = not Empty =~ = Regex

What does special variable $$ mean/do?

The The process number of the current shell. The process ID which the script is executing.

What does special variable $? mean/do?

The exit status of the last command executed. typically As a rule, if exit status is 0 then they are successful and 1 if they were unsuccessful.

How can you define a variable?

The name can only use A-Z or 0-9 and _ Convention states to only shell variables in UpperCase A variable simply points to the data and the shell enables you to create, assign, and delete variables.

What are Variable types?

There are 3 types of variables. Local, Environment and Shell local variable is a variable present within the current instance of shell environment variable is can be run by any child process of the shell the shell variable is this is set by the shell and required to function correctly

What do you know about the Linux Daemons?

They are background processes which perform a operation at some predefined time or in response to some event

What is the select loop?

This is a easy way to create a numbered menu from which users can select options. it is useful when you need to ask the user to choose one or more items from list

What does special variable $! mean/do?

This is the process number of the last background command.

What does it mean to unset a variable?

This will delete a variable and tell the shell to remove from list of variables that it tracks. -Cant access the stored value in the variable after it has been unset done by unset command

What are array variable?

This will provides a method to group and hold multiple values at the same time. Instead of creating a new name for each variable, it call all be stored in a single array variable.

How will you remove all the running processes without restarting the machine?

Use the Linux <disown> command to remove the jobs from current shell system, to remove all running you can use < disown -r>

How can you make commands read only?

Use the readonly command, readonly "variblename"

Why use the case....esac statement

When you want to perform a multiway branch which depends on a single variable, its best to use a case...esac statement

What is a while loop?

While loop lets you execute commands until a condition if met, useful for manipulating the value of a variable repeatedly. a=0 while [ $a -it 10 ] do echo $a a=`expr $a +1` done will write this until it is less then 10

How do you Terminate an Ongoing Process?

You can identify running processes by unique process id or PID use <kill 0> to call all

How to put comments in a script?

You can use a hash sign #

What Boolean Operators are supported by a Bourne again Shell

[ ! false ] This is a logical negation, turns a true condition into false [ $a -It 20 -o $b -gt 100 ] This is a or (-o) operand is true, then condition become true.

What relational operators exist?

[ $a -eq $b ] is not true [ $a -ne $b ] is true [ $a -gt $b ] check if left is greater then right [ $a -It $b] check if left is less then right [ $a -ge $b] check if left is greater or equal to right [ $a -le $b ] check if left is less then or equal to right **The inside square braces must have spaces around them.

How can create a array variable?

array_name[index]=value array_name is the name of the array index is the index of the item in the array that you want tot set value is the value you want to set for that item. ${array_name[index]} Both ${array_name[@]} ${array_name[*]) will output all the values in the array

What are the different modes in which we can use the Vi editor?

command mode- starts when you launch the vi. Edit mode: allows editing of text Ex-mode: to interact with the vi editor and provides instructions to process a file.

What is a for loop for?

for loop operates on lists of items, will repeat set of commands for every item in a list. for var in word1 word2 .....wordN do Statement done

What does the read function do?

take input from user and puts it in a "variable" read PERSON -Variable just points to your data

How can you check Memory and CPU stats

vm stat command can check this and for CPU you can use sar command


संबंधित स्टडी सेट्स

Chapter 2- The California State Department of Real Estate

View Set

Gramm-Leach-Bliley Act (Privacy of Consumer Financial Information)

View Set