for sed elif
#!/bin/bash
for i in a b c
do
echo $i
done
for i in a b c
do
echo $i
done
bash for1
a
b
c
-----------
GNU sed has the option -i to update the file
sed s/for/sss/g for1 -i
ubuntu2@ubuntu2:~/Documents/shellscripting$ cat for1
#!/bin/bash
sss i in a b c
do
echo $i
done
---------
How to add text to the particular line in the file:
sed -i '1s/^/task goes here\n/' for1
---------
How to add text to the particular line in the file:
sed -i '1s/^/task goes here\n/' for1
------------
----------
cat for1
#!/bin/bash
for i in a b c
do
echo $i
done
if [ "$?" -ne "0" ]; then
echo not ok
else
echo ok
fi
sed -n '1p;$p' file.txt
will print 1st and last line of file.txt .----------
cat for1
#!/bin/bash
for i in a b c
do
echo $i
done
if [ "$?" -ne "0" ]; then
echo not ok
else
echo ok
fi
bash for1
a
b
c
ok
-----------
cat ifelif1
#!/bin/bash
# elif example
##################
echo Hi
OS=`uname -s`
if [ "$OS" = "Linux" ]; then
echo Linux
elif [ "$OS" = "UNIX" ]; then
echo UNIX
fi
cat ifelif1
#!/bin/bash
# elif example
##################
echo Hi
OS=`uname -s`
if [ "$OS" = "Linux" ]; then
echo Linux
elif [ "$OS" = "UNIX" ]; then
echo UNIX
fi
bash ifelif1
Hi
Linux
-------------
cat whileread
#/bin/bash
while read -p "Enter file name: " filename
do
if [ ! -e "$filename" ]; then
echo File doesnt exist
continue
fi
if [ -f "$filename" ]; then
echo Regular file
elif [ -d $filename ]; then
echo Directory
fi
done
cat whileread
#/bin/bash
while read -p "Enter file name: " filename
do
if [ ! -e "$filename" ]; then
echo File doesnt exist
continue
fi
if [ -f "$filename" ]; then
echo Regular file
elif [ -d $filename ]; then
echo Directory
fi
done
bash whileread
Enter file name: t
Directory
Enter file name: for1
Regular file
--------------
Comments
Post a Comment