Awọn ibeere Ifọrọwanilẹnuwo iṣe ati Awọn Idahun lori Ikarahun Ikarahun Shell
Pẹlu idahun ti o lagbara ti a ngba lori awọn nkan Jomitoro jara, akọkọ ti iru rẹ lori eyikeyi Linux How-to oju opo wẹẹbu ni irisi Awọn ayanfẹ, Awọn esi ni asọye ati lori Adirẹsi Imeeli ti ara ẹni jẹ ki a lọ lati nkan kan si ekeji nkan.
Eyi ni ọna asopọ si awọn nkan jara Awọn ibere ijomitoro ti a tẹjade tẹlẹ lori linux-console.net, nibi ti a ti bo ọpọlọpọ awọn akọle bii,, FTP, MySQL, Afun, Iwe afọwọkọ, Awọn ofin Linux, ati bẹbẹ lọ.
Tẹsiwaju si jara ti o wa loke nibi a nbọ pẹlu 5 iyanu Awọn ibeere Lainos Lainos miiran ati idahun wọn. Rẹ (Awọn onkawe linux-console.net ati Awọn alejo loorekoore) atilẹyin nigbagbogbo nilo lati jẹ ki o ṣaṣeyọri.
Bayi ṣẹda faili kan ti a pe ni 'userstats.sh' ki o ṣafikun koodu atẹle si rẹ.
#!/bin/bash echo "Hello, $LOGNAME" echo "Current date is `date`" echo "User is `who i am`" echo "Current directory `pwd`"
Gbe igbanilaaye ṣiṣẹ ati ṣiṣe akosile bi o ṣe han ni isalẹ.
# chmod 755 userstats.sh # ./userstats.sh
Hello, avi Current date is Sat Jun 7 13:05:29 IST 2014 User is avi pts/0 2014-06-07 11:59 (:0) Current directory /home/avi/Desktop
Lẹẹkansi ṣẹda faili kan ti a pe ni 'two-numbers.sh' ki o ṣafikun akoonu atẹle si rẹ.
#!/bin/bash # The Shebang if [ $# -ne 2 ] # If two Inputs are not received from Standard Input then # then execute the below statements echo "Usage - $0 x y" # print on standard output, how-to use the script (Usage - ./1.sh x y ) echo " Where x and y are two nos for which I will print sum" # print on standard output, “Where x and y are two nos for which I will print sum ” exit 1 # Leave shell in Error Stage and before the task was successfully carried out. fi # End of the if Statement. echo "Sum of $1 and $2 is `expr $1 + $2`" # If the above condition was false and user Entered two numbers as a command Line Argument, it will show the sum of the entered numbers.
Ṣeto igbanilaaye alaṣẹ lori faili naa ki o ṣiṣẹ iwe afọwọkọ bi a ṣe han ni isalẹ.
# chmod 755 two-numbers.sh
Ipo 1: Nṣiṣẹ iwe afọwọkọ laisi titẹ awọn nọmba meji sii bi ariyanjiyan laini aṣẹ, iwọ yoo gba abajade wọnyi.
# ./two-numbers.sh Usage - ./two-numbers.sh x y Where x and y are two nos for which I will print sum
Ipò 2: Nigbati a ba tẹ Awọn nọmba sii bi ariyanjiyan laini aṣẹ iwọ yoo gba abajade bi o ti han.
$ ./two-numbers.sh 4 5 Sum of 4 and 5 is 9
Nitorinaa iwe afọwọkọ ikarahun ti o wa loke mu ipo naa ṣẹ gẹgẹbi a daba ni ibeere naa.
- 1li Jẹ ki Nọmba Input = n 2. Ṣeto rev = 0, sd = 0 (Yiyipada ati digitis ẹyọkan ti a ṣeto si 0) 3. n% 10, yoo wa ki o fun ni ẹyọkan osi nọmba pupọ 4. nọmba ti yiyipada ti wa ni ipilẹṣẹ bi rev * 10 + sd 5. Dinku Nọmba Input (n) nipasẹ 1.
- 6. ti o ba n> 0, lẹhinna goto igbese 3 miiran goto setp 7
- 7. Tẹjade
Bayi lẹẹkansi, ṣẹda faili kan ti a pe ni 'numbers.sh' ki o ṣafikun koodu ti a fun ni wọnyi.
#!/bin/bash if [ $# -ne 1 ] then echo "Usage: $0 number" echo " I will find reverse of given number" echo " For eg. $0 0123, I will print 3210" exit 1 fi n=$1 rev=0 sd=0 while [ $n -gt 0 ] do sd=`expr $n % 10` rev=`expr $rev \* 10 + $sd` n=`expr $n / 10` done echo "Reverse number is $rev"
Fifun igbanilaaye ṣiṣe lori faili naa ki o ṣiṣẹ iwe afọwọkọ bi a ṣe han ni isalẹ.
# chmod 755 numbers.h
Ipò 1: Nigbati a ko ba pese Input bi ariyanjiyan laini aṣẹ, iwọ yoo gba iṣelọpọ wọnyi.
./numbers.sh Usage: ./numbers.sh number I will find reverse of given number For eg. ./2.sh 123, I will print 321
Ipò 2: Nigbati a ba pese Input bi ariyanjiyan ila laini aṣẹ.
$ ./numbers.sh 10572 Reverse number is 27501
Iwe afọwọkọ ti o wa loke ṣiṣẹ ni pipe ati pe iṣelọpọ jẹ ohun ti a nilo.
Fun apẹẹrẹ, ṣiṣe aṣẹ atẹle lati ṣe iṣiro awọn nọmba ni akoko gidi nipa lilo pipaṣẹ bc bi o ti han.
$ echo 7.56 + 2.453 | bc 10.013
# pi 100 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
O han ni! A gbọdọ ni package ‘pi’ ti fi sii. Kan ṣe apt tabi yum lati gba package ti o nilo lati fi ‘pi’ sori ẹrọ pinpin ti o nlo.
Iyẹn ni gbogbo fun bayi. Emi yoo wa nibi lẹẹkansi pẹlu nkan miiran ti o nifẹ laipẹ. Titi lẹhinna wa ni aifwy ati sopọ si linux-console.net. Maṣe gbagbe lati pese wa pẹlu rẹ awọn esi ti o niyelori ni apakan asọye ni isalẹ.