Академический Документы
Профессиональный Документы
Культура Документы
ANS
cat filename.txt | cut -c 10-20
How would you print just the 25th line in a file (smallest possible script
please)?
ANS
sed -n '25p' filename.txt
How would you replace the n character in a file with some xyz?
%s/n/xyz/g
How would you replace the n character in a file wi...
script a.sh :-
----------
export A=3
B=5
sh b.sh
--------
script b.sh :-
-----------
echo "exported variable $A is :- $A"
echo "Variable $B -- $B "
---------
exported variable is visible to the child processes while the normal variables are not.
The Shell variable which is exported would available to all the programs outside the Shell also.
And the shell variable which is not exported, would available for that shell or for the shell
program only, in which the variable is declared.
How will you list only the empty lines in a file (using grep)?
this command will gives all the blank line including those having space and tabs (if
pressed)only
OR
We can do this efficiently through awk script
awk '{
if (NF == 0)
{
print "Here comes the empty line"
print $0
}
}' filename
OR
This is done by 'at' command in HPUX and Sun solaris or 'cron' command can be used too.
Mukesh Chauhan –Bangalore
1. There are two ways to schedule a script to run exactly at 4:00 AM every morning
a: CRONTAB
b. AT (at command executes only once)
Crontab format
* * * * * <command>
<minute> <hour> <date> <month> <day_of_the_week> command
<0-59> <0-23> <1-31> <1-12> <0-7> command
OR
1st step
$ cat > cmdfile
//<Minute> <Hour> <Day Of Month> <Day Of Week> <Command>
0 4 * * <Command>
Ctrl d
2nd Step
crontab cmdfile
view <filename> is a better option. It will not allow writing to a file normally, unless done
forcefully like "wq!" or "x!"...
"vi -R filename"
OR
In a shell script, you can open a file in read only mode by using O_RDONLY
Syntax - open(<filename>,O_RDONLY)
more <file_name> is the best option.
OR
... then you open it the same way you open any other file. The system will simply prevent you
from writing to it.
If you mean open a file in Unix such that you can not write to the file, even though you
otherwise would be allowed because you do have write permission ...
... then it depends on what mechanism you use to open the file. Others have already answered
for opening with the "vi" editor. Other programs, such as "emacs", or other text editors, would
have other ways.
What are the different kinds of loops available in shell script?
for, if, while, case
Broadly categorised in 3
for
while
until
How do you read arguments in a shell program - $1, $2 ?
#!/bin/sh
for i in $*
do
echo $i
done
On executig the above script with any number of command-line arguments it will display all the
parametsrs.
OR
$1 would be the first command line argument, $2 the second, and so on
$0 is the name of the script or function
OR
Shell script accepts parameters in following format...
$1 : first
$2 : second....so on upto
$9 : 9th param
whereas $0 : gives script/function name
If your script has more than 9 params then accept in following way...
${12} : 12th param
${18} : 18th param
OR
by using :
exec<$1 or exec<$2
When you login to a c shell, which script would be run first? (before
the terminal is ready for the user)
For C shell ,
first /etc/.login script is run & after that
~/.login is run & then ~/.cshrc is run.
OR