Guest User

Untitled

a guest
Dec 5th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.18 KB | None | 0 0
  1. user1@lab:~$ touch myscript
  2.  
  3. user1@lab:~$ ls -l
  4. total 8
  5. -rw-rw-r-- 1 user1 user1 0 Nov 5 17:16 myscript
  6. -rw------- 1 user1 user1 2 Oct 27 07:41 nano.save
  7. -rw-rw-r-- 1 user1 user1 0 Nov 4 18:45 pids
  8. -rw-rw-r-- 1 user1 user1 0 Oct 20 09:29 test.sh
  9. -rwxrwxr-x 1 user1 user1 26 Oct 27 07:24 text
  10.  
  11. user1@lab:~$ chmod +x ./myscript
  12.  
  13. user1@lab:~$ ls -l
  14. total 8
  15. -rwxrwxr-x 1 user1 user1 0 Nov 5 17:16 myscript
  16. -rw------- 1 user1 user1 2 Oct 27 07:41 nano.save
  17. -rw-rw-r-- 1 user1 user1 0 Nov 4 18:45 pids
  18. -rw-rw-r-- 1 user1 user1 0 Oct 20 09:29 test.sh
  19. -rwxrwxr-x 1 user1 user1 26 Oct 27 07:24 text
  20.  
  21. user1@lab:~$ nano ./myscript
  22.  
  23. GNU nano 2.5.3 File: ./myscript Modified
  24.  
  25. #!/bin/bash
  26. # This is a comment
  27.  
  28. pwd
  29. whoami
  30.  
  31. user1@lab:~$ ./myscript
  32. /home/user1
  33. user1
  34.  
  35. -----------------------------------------------------------------------------------------
  36.  
  37. user1@lab:~$ nano ./myscript
  38.  
  39. GNU nano 2.5.3 File: ./myscript Modified
  40.  
  41. #!/bin/bash
  42. # our comment is here
  43.  
  44. echo "The current directory is:"
  45. pwd
  46. echo "The user logged in is:"
  47. whoami
  48.  
  49. user1@lab:~$ ./myscript
  50. The current directory is:
  51. /home/user1
  52. The user logged in is:
  53. user1
  54.  
  55. -----------------------------------------------------------------------------------------
  56.  
  57. user1@lab:~$ nano ./myscript
  58.  
  59. GNU nano 2.5.3 File: ./myscript Modified
  60.  
  61. #!/bin/bash
  62. # display user home
  63.  
  64. echo "Home for the current user is: $HOME"
  65.  
  66. user1@lab:~$ ./myscript
  67. Home for the current user is: /home/user1
  68.  
  69. -----------------------------------------------------------------------------------------
  70.  
  71. user1@lab:~$ nano ./myscript
  72.  
  73. GNU nano 2.5.3 File: ./myscript Modified
  74.  
  75. #!/bin/bash
  76.  
  77. echo "I have $1 in my pocket"
  78. echo "I have \$1 in my pocket"
  79.  
  80. user1@lab:~$ ./myscript
  81. I have in my pocket
  82. I have $1 in my pocket
  83.  
  84. user1@lab:~$ ./myscript web
  85. I have web in my pocket
  86. I have $1 in my pocket
  87.  
  88. -----------------------------------------------------------------------------------------
  89.  
  90. user1@lab:~$ nano ./myscript
  91.  
  92. GNU nano 2.5.3 File: ./myscript Modified
  93.  
  94. #!/bin/bash
  95. # testing variables
  96.  
  97. grade=5
  98. person="Adam"
  99. echo "$person is a good boy, he is in grade $grade"
  100.  
  101. user1@lab:~$ ./myscript
  102. Adam is a good boy, he is in grade 5
  103.  
  104. -----------------------------------------------------------------------------------------
  105.  
  106. user1@lab:~$ nano ./myscript
  107.  
  108. GNU nano 2.5.3 File: ./myscript Modified
  109.  
  110. #!/bin/bash
  111.  
  112. mydir=`pwd`
  113. echo $mydir
  114.  
  115. mydir1=$(pwd)
  116. echo $mydir1
  117.  
  118. user1@lab:~$ ./myscript
  119. /home/user1
  120. /home/user1
  121.  
  122. -----------------------------------------------------------------------------------------
  123.  
  124. user1@lab:~$ nano ./myscript
  125.  
  126. GNU nano 2.5.3 File: ./myscript Modified
  127.  
  128. #!/bin/bash
  129.  
  130. var1=$(( 5 + 5 ))
  131. echo $var1
  132. var2=$(( $var1 * 2 ))
  133. echo $var2
  134.  
  135. user1@lab:~$ ./myscript
  136. 10
  137. 20
  138.  
  139. -----------------------------------------------------------------------------------------
  140.  
  141. user1@lab:~$ nano ./myscript
  142.  
  143. GNU nano 2.5.3 File: ./myscript Modified
  144.  
  145. #!/bin/bash
  146.  
  147. if pwd
  148. then
  149. echo "It works"
  150. fi
  151.  
  152. user1@lab:~$ ./myscript
  153. /home/user1
  154. It works
  155.  
  156. -----------------------------------------------------------------------------------------
  157.  
  158. user1@lab:~$ nano ./myscript
  159.  
  160. GNU nano 2.5.3 File: ./myscript Modified
  161.  
  162. #!/bin/bash
  163.  
  164. user=user1
  165.  
  166. if grep $user /etc/passwd
  167. then
  168. echo "The user $user Exists"
  169. fi
  170.  
  171. user1@lab:~$ ./myscript
  172. user1:x:1000:1000::/home/user1:/bin/bash
  173. user10:x:1009:1009::/home/user10:/bin/bash
  174. The user user1 Exists
  175.  
  176. -----------------------------------------------------------------------------------------
  177.  
  178. user1@lab:~$ nano ./myscript
  179.  
  180. GNU nano 2.5.3 File: ./myscript Modified
  181.  
  182. #!/bin/bash
  183.  
  184. user=anotherUser
  185.  
  186. if grep $user /etc/passwd
  187. then
  188. echo "The user $user Exists"
  189. else
  190. echo "The user $user doesn't exist"
  191. fi
  192.  
  193. user1@lab:~$ ./myscript
  194. The user anotherUser doesn't exist
  195.  
  196. -----------------------------------------------------------------------------------------
  197.  
  198. user1@lab:~$ nano ./myscript
  199.  
  200. GNU nano 2.5.3 File: ./myscript Modified
  201.  
  202. #!/bin/bash
  203.  
  204. user=anotherUser
  205.  
  206. if grep $user /etc/passwd
  207. then
  208. echo "The user $user Exists"
  209. elif ls /home
  210. then
  211. echo "The user doesn't exist but anyway there is a directory under /home"
  212. fi
  213.  
  214. user1@lab:~$ ./myscript
  215. user1 user10 user2 user3 user4 user5 user6 user7 user8 user9
  216. The user doesn't exist but anyway there is a directory under /home
  217.  
  218. -----------------------------------------------------------------------------------------
  219.  
  220. user1@lab:~$ nano ./myscript
  221.  
  222. GNU nano 2.5.3 File: ./myscript Modified
  223.  
  224. #!/bin/bash
  225.  
  226. val1=6
  227. if [ $val1 -gt 5 ]
  228. then
  229. echo "The test value $val1 is greater than 5"
  230. else
  231. echo "The test value $val1 is not greater than 5"
  232. fi
  233.  
  234. user1@lab:~$ ./myscript
  235. The test value 6 is greater than 5
  236.  
  237. -----------------------------------------------------------------------------------------
  238.  
  239. user1@lab:~$ nano ./myscript
  240.  
  241. GNU nano 2.5.3 File: ./myscript Modified
  242.  
  243. #!/bin/bash
  244.  
  245. user="user1"
  246.  
  247. if [ $user = $USER ]
  248. then
  249. echo "The user $user is the current logged in user"
  250. fi
  251.  
  252. user1@lab:~$ ./myscript
  253. The user user1 is the current logged in user
  254.  
  255. -----------------------------------------------------------------------------------------
  256.  
  257. user1@lab:~$ nano ./myscript
  258.  
  259. GNU nano 2.5.3 File: ./myscript Modified
  260.  
  261. #!/bin/bash
  262.  
  263. val1=text
  264. val2="another text"
  265.  
  266. if [ $val1 \> $val2 ]
  267. then
  268. echo "$val1 is greater than $val2"
  269. else
  270. echo "$val1 is less than $val2"
  271. fi
  272.  
  273. user1@lab:~$ ./myscript
  274. ./myscript: line 6: [: too many arguments
  275. text is less than another text
  276.  
  277. user1@lab:~$ nano ./myscript
  278.  
  279. GNU nano 2.5.3 File: ./myscript Modified
  280.  
  281. #!/bin/bash
  282.  
  283. val1=text
  284. val2="another text"
  285.  
  286. if [ $val1 \> "$val2" ]
  287. then
  288. echo "$val1 is greater than $val2"
  289. else
  290. echo "$val1 is less than $val2"
  291. fi
  292.  
  293. user1@lab:~$ ./myscript
  294. text is greater than another text
  295.  
  296. -----------------------------------------------------------------------------------------
  297.  
  298. user1@lab:~$ nano ./myscript
  299.  
  300. GNU nano 2.5.3 File: ./myscript Modified
  301.  
  302. #!/bin/bash
  303.  
  304. val1=User1
  305. val2=user1
  306.  
  307. if [ $val1 \> $val2 ]
  308. then
  309. echo "$val1 is greater than $val2"
  310. else
  311. echo "$val1 is less than $val2"
  312. fi
  313.  
  314. user1@lab:~$ ./myscript
  315. User1 is less than user1
  316.  
  317. user1@lab:~$ echo -e "User1\nuser1\nWeb\nIT\nprograming\n2017\n.." > ./myfile
  318.  
  319. user1@lab:~$ ls -l
  320. total 16
  321. -rw-rw-r-- 1 user1 user1 38 Nov 5 19:15 myfile
  322. -rwxrwxr-x 1 user1 user1 138 Nov 5 18:54 myscript
  323. -rw------- 1 user1 user1 2 Oct 27 07:41 nano.save
  324. -rw-rw-r-- 1 user1 user1 0 Nov 4 18:45 pids
  325. -rw-rw-r-- 1 user1 user1 0 Oct 20 09:29 test.sh
  326. -rwxrwxr-x 1 user1 user1 26 Oct 27 07:24 text
  327.  
  328. user1@lab:~$ cat ./myfile
  329. User1
  330. user1
  331. Web
  332. IT
  333. programing
  334. 2017
  335. ..
  336. user1@lab:~$ sort ./myfile
  337. ..
  338. 2017
  339. IT
  340. User1
  341. Web
  342. programing
  343. user1
  344.  
  345. -----------------------------------------------------------------------------------------
  346.  
  347. user1@lab:~$ nano ./myscript
  348.  
  349. GNU nano 2.5.3 File: ./myscript Modified
  350.  
  351. #!/bin/bash
  352.  
  353. mydir=/home/user1
  354.  
  355. if [ -d $mydir ]
  356. then
  357. echo "The $mydir directory exists"
  358. cd $mydir
  359. ls
  360. else
  361. echo "The $mydir directory does not exist"
  362. fi
  363.  
  364. user1@lab:~$ ./myscript
  365. The /home/user1 directory exists
  366. myfile myscript nano.save pids test.sh text
  367.  
  368. -----------------------------------------------------------------------------------------
  369.  
  370. user1@lab:~$ nano ./myscript
  371.  
  372. GNU nano 2.5.3 File: ./myscript Modified
  373.  
  374. #!/bin/bash
  375.  
  376. for var in first second third fourth fifth
  377. do
  378. echo The $var item
  379. done
  380.  
  381. user1@lab:~$ ./myscript
  382. The first item
  383. The second item
  384. The third item
  385. The fourth item
  386. The fifth item
  387.  
  388. -----------------------------------------------------------------------------------------
  389.  
  390. user1@lab:~$ nano ./myscript
  391.  
  392. GNU nano 2.5.3 File: ./myscript Modified
  393.  
  394. #!/bin/bash
  395.  
  396. for var in first "the second" "the third" "I'll do it"
  397. do
  398. echo "This is: $var"
  399. done
  400.  
  401. user1@lab:~$ ./myscript
  402. This is: first
  403. This is: the second
  404. This is: the third
  405. This is: I'll do it
  406.  
  407. -----------------------------------------------------------------------------------------
  408.  
  409. user1@lab:~$ nano ./myscript
  410.  
  411. GNU nano 2.5.3 File: ./myscript Modified
  412.  
  413. #!/bin/bash
  414.  
  415. file="myfile"
  416.  
  417. for var in $(cat $file)
  418. do
  419. echo " $var"
  420. done
  421.  
  422. user1@lab:~$ ./myscript
  423. User1
  424. user1
  425. Web
  426. IT
  427. programing
  428. 2017
  429. ..
  430.  
  431. -----------------------------------------------------------------------------------------
  432.  
  433. user1@lab:~$ nano ./myscript
  434.  
  435. GNU nano 2.5.3 File: ./myscript Modified
  436.  
  437. #!/bin/bash
  438.  
  439. file="/etc/passwd"
  440.  
  441. IFS=$'\n'
  442.  
  443. for var in $(cat $file)
  444. do
  445. echo " $var"
  446. done
  447.  
  448. user1@lab:~$ ./myscript
  449. root:x:0:0:root:/root:/bin/bash
  450. daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
  451. bin:x:2:2:bin:/bin:/usr/sbin/nologin
  452. sys:x:3:3:sys:/dev:/usr/sbin/nologin
  453. sync:x:4:65534:sync:/bin:/bin/sync
  454. games:x:5:60:games:/usr/games:/usr/sbin/nologin
  455. man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
  456. lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
  457. mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
  458. news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
  459. uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
  460. proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
  461. www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
  462. backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
  463. list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
  464. irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
  465. gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
  466. nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
  467. systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false
  468. systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false
  469. systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false
  470. systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false
  471. syslog:x:104:109::/home/syslog:/bin/false
  472. _apt:x:105:65534::/nonexistent:/bin/false
  473. postfix:x:106:112::/var/spool/postfix:/bin/false
  474. sshd:x:107:65534::/var/run/sshd:/usr/sbin/nologin
  475. uuidd:x:108:115::/run/uuidd:/bin/false
  476. messagebus:x:109:116::/var/run/dbus:/bin/false
  477. user1:x:1000:1000::/home/user1:/bin/bash
  478. user2:x:1001:1001::/home/user2:/bin/bash
  479. user3:x:1002:1002::/home/user3:/bin/bash
  480. user4:x:1003:1003::/home/user4:/bin/bash
  481. user5:x:1004:1004::/home/user5:/bin/bash
  482. user6:x:1005:1005::/home/user6:/bin/bash
  483. user7:x:1006:1006::/home/user7:/bin/bash
  484. user8:x:1007:1007::/home/user8:/bin/bash
  485. user9:x:1008:1008::/home/user9:/bin/bash
  486. user10:x:1009:1009::/home/user10:/bin/bash
  487.  
  488. -----------------------------------------------------------------------------------------
  489.  
  490. user1@lab:~$ nano ./myscript
  491.  
  492. GNU nano 2.5.3 File: ./myscript Modified
  493.  
  494. #!/bin/bash
  495.  
  496. for file in /home/user1/*
  497. do
  498. if [ -d "$file" ]
  499. then
  500. echo "$file is a directory"
  501. elif [ -f "$file" ]
  502. then
  503. echo "$file is a file"
  504. fi
  505. done
  506.  
  507. user1@lab:~$ ./myscript
  508. /home/user1/myfile is a file
  509. /home/user1/myscript is a file
  510. /home/user1/nano.save is a file
  511. /home/user1/pids is a file
  512. /home/user1/test.sh is a file
  513. /home/user1/text is a file
  514.  
  515. -----------------------------------------------------------------------------------------
  516.  
  517. user1@lab:~$ nano ./myscript
  518.  
  519. GNU nano 2.5.3 File: ./myscript Modified
  520.  
  521. #!/bin/bash
  522.  
  523. for (( i=1; i <= 10; i++ ))
  524. do
  525. echo "number is $i"
  526. done
  527.  
  528. user1@lab:~$ ./myscript
  529. number is 1
  530. number is 2
  531. number is 3
  532. number is 4
  533. number is 5
  534. number is 6
  535. number is 7
  536. number is 8
  537. number is 9
  538. number is 10
  539.  
  540. -----------------------------------------------------------------------------------------
  541.  
  542. user1@lab:~$ nano ./myscript
  543.  
  544. GNU nano 2.5.3 File: ./myscript Modified
  545.  
  546. #!/bin/bash
  547.  
  548. var1=5
  549.  
  550. while [ $var1 -gt 0 ]
  551. do
  552. echo $var1
  553. var1=$[ $var1 - 1 ]
  554. done
  555.  
  556. user1@lab:~$ ./myscript
  557. 5
  558. 4
  559. 3
  560. 2
  561. 1
  562.  
  563. -----------------------------------------------------------------------------------------
  564.  
  565. user1@lab:~$ nano ./myscript
  566.  
  567. GNU nano 2.5.3 File: ./myscript Modified
  568.  
  569. #!/bin/bash
  570.  
  571. for (( a = 1; a <= 3; a++ ))
  572. do
  573. echo "Start $a:"
  574. for (( b = 1; b <= 3; b++ ))
  575. do
  576. echo " Inner loop: $b"
  577. done
  578. done
  579.  
  580. user1@lab:~$ ./myscript
  581. Start 1:
  582. Inner loop: 1
  583. Inner loop: 2
  584. Inner loop: 3
  585. Start 2:
  586. Inner loop: 1
  587. Inner loop: 2
  588. Inner loop: 3
  589. Start 3:
  590. Inner loop: 1
  591. Inner loop: 2
  592. Inner loop: 3
  593.  
  594. -----------------------------------------------------------------------------------------
  595.  
  596. user1@lab:~$ nano ./myscript
  597.  
  598. GNU nano 2.5.3 File: ./myscript Modified
  599.  
  600. #!/bin/bash
  601.  
  602. IFS=$'\n'
  603.  
  604. for entry in $(cat /etc/passwd)
  605. do
  606. echo "Values in $entry -"
  607. IFS=:
  608. for value in $entry
  609. do
  610. echo " $value"
  611. done
  612. done
  613.  
  614. user1@lab:~$ ./myscript
  615. Values in root:x:0:0:root:/root:/bin/bash -
  616. root
  617. x
  618. 0
  619. 0
  620. root
  621. /root
  622. /bin/bash
  623. Values in daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin -
  624. daemon
  625. x
  626. 1
  627. 1
  628. daemon
  629. /usr/sbin
  630. /usr/sbin/nologin
  631. Values in bin:x:2:2:bin:/bin:/usr/sbin/nologin -
  632. bin
  633. x
  634. 2
  635. 2
  636. bin
  637. /bin
  638. /usr/sbin/nologin
  639. Values in sys:x:3:3:sys:/dev:/usr/sbin/nologin -
  640. sys
  641. x
  642. 3
  643. 3
  644. sys
  645. /dev
  646. /usr/sbin/nologin
  647. Values in sync:x:4:65534:sync:/bin:/bin/sync -
  648. sync
  649. x
  650. 4
  651. 65534
  652. sync
  653. /bin
  654. /bin/sync
  655. Values in games:x:5:60:games:/usr/games:/usr/sbin/nologin -
  656. games
  657. x
  658. 5
  659. 60
  660. games
  661. /usr/games
  662. /usr/sbin/nologin
  663. Values in man:x:6:12:man:/var/cache/man:/usr/sbin/nologin -
  664. man
  665. x
  666. 6
  667. 12
  668. man
  669. /var/cache/man
  670. /usr/sbin/nologin
  671. Values in lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin -
  672. lp
  673. x
  674. 7
  675. 7
  676. lp
  677. /var/spool/lpd
  678. /usr/sbin/nologin
  679. Values in mail:x:8:8:mail:/var/mail:/usr/sbin/nologin -
  680. mail
  681. x
  682. 8
  683. 8
  684. mail
  685. /var/mail
  686. /usr/sbin/nologin
  687. Values in news:x:9:9:news:/var/spool/news:/usr/sbin/nologin -
  688. news
  689. x
  690. 9
  691. 9
  692. news
  693. /var/spool/news
  694. /usr/sbin/nologin
  695. Values in uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin -
  696. uucp
  697. x
  698. 10
  699. 10
  700. uucp
  701. /var/spool/uucp
  702. /usr/sbin/nologin
  703. Values in proxy:x:13:13:proxy:/bin:/usr/sbin/nologin -
  704. proxy
  705. x
  706. 13
  707. 13
  708. proxy
  709. /bin
  710. /usr/sbin/nologin
  711. Values in www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin -
  712. www-data
  713. x
  714. 33
  715. 33
  716. www-data
  717. /var/www
  718. /usr/sbin/nologin
  719. Values in backup:x:34:34:backup:/var/backups:/usr/sbin/nologin -
  720. backup
  721. x
  722. 34
  723. 34
  724. backup
  725. /var/backups
  726. /usr/sbin/nologin
  727. Values in list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin -
  728. list
  729. x
  730. 38
  731. 38
  732. Mailing List Manager
  733. /var/list
  734. /usr/sbin/nologin
  735. Values in irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin -
  736. irc
  737. x
  738. 39
  739. 39
  740. ircd
  741. /var/run/ircd
  742. /usr/sbin/nologin
  743. Values in gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin -
  744. gnats
  745. x
  746. 41
  747. 41
  748. Gnats Bug-Reporting System (admin)
  749. /var/lib/gnats
  750. /usr/sbin/nologin
  751. Values in nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin -
  752. nobody
  753. x
  754. 65534
  755. 65534
  756. nobody
  757. /nonexistent
  758. /usr/sbin/nologin
  759. Values in systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false -
  760. systemd-timesync
  761. x
  762. 100
  763. 102
  764. systemd Time Synchronization,,,
  765. /run/systemd
  766. /bin/false
  767. Values in systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false -
  768. systemd-network
  769. x
  770. 101
  771. 103
  772. systemd Network Management,,,
  773. /run/systemd/netif
  774. /bin/false
  775. Values in systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false -
  776. systemd-resolve
  777. x
  778. 102
  779. 104
  780. systemd Resolver,,,
  781. /run/systemd/resolve
  782. /bin/false
  783. Values in systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false -
  784. systemd-bus-proxy
  785. x
  786. 103
  787. 105
  788. systemd Bus Proxy,,,
  789. /run/systemd
  790. /bin/false
  791. Values in syslog:x:104:109::/home/syslog:/bin/false -
  792. syslog
  793. x
  794. 104
  795. 109
  796.  
  797. /home/syslog
  798. /bin/false
  799. Values in _apt:x:105:65534::/nonexistent:/bin/false -
  800. _apt
  801. x
  802. 105
  803. 65534
  804.  
  805. /nonexistent
  806. /bin/false
  807. Values in postfix:x:106:112::/var/spool/postfix:/bin/false -
  808. postfix
  809. x
  810. 106
  811. 112
  812.  
  813. /var/spool/postfix
  814. /bin/false
  815. Values in sshd:x:107:65534::/var/run/sshd:/usr/sbin/nologin -
  816. sshd
  817. x
  818. 107
  819. 65534
  820.  
  821. /var/run/sshd
  822. /usr/sbin/nologin
  823. Values in uuidd:x:108:115::/run/uuidd:/bin/false -
  824. uuidd
  825. x
  826. 108
  827. 115
  828.  
  829. /run/uuidd
  830. /bin/false
  831. Values in messagebus:x:109:116::/var/run/dbus:/bin/false -
  832. messagebus
  833. x
  834. 109
  835. 116
  836.  
  837. /var/run/dbus
  838. /bin/false
  839. Values in user1:x:1000:1000::/home/user1:/bin/bash -
  840. user1
  841. x
  842. 1000
  843. 1000
  844.  
  845. /home/user1
  846. /bin/bash
  847. Values in user2:x:1001:1001::/home/user2:/bin/bash -
  848. user2
  849. x
  850. 1001
  851. 1001
  852.  
  853. /home/user2
  854. /bin/bash
  855. Values in user3:x:1002:1002::/home/user3:/bin/bash -
  856. user3
  857. x
  858. 1002
  859. 1002
  860.  
  861. /home/user3
  862. /bin/bash
  863. Values in user4:x:1003:1003::/home/user4:/bin/bash -
  864. user4
  865. x
  866. 1003
  867. 1003
  868.  
  869. /home/user4
  870. /bin/bash
  871. Values in user5:x:1004:1004::/home/user5:/bin/bash -
  872. user5
  873. x
  874. 1004
  875. 1004
  876.  
  877. /home/user5
  878. /bin/bash
  879. Values in user6:x:1005:1005::/home/user6:/bin/bash -
  880. user6
  881. x
  882. 1005
  883. 1005
  884.  
  885. /home/user6
  886. /bin/bash
  887. Values in user7:x:1006:1006::/home/user7:/bin/bash -
  888. user7
  889. x
  890. 1006
  891. 1006
  892.  
  893. /home/user7
  894. /bin/bash
  895. Values in user8:x:1007:1007::/home/user8:/bin/bash -
  896. user8
  897. x
  898. 1007
  899. 1007
  900.  
  901. /home/user8
  902. /bin/bash
  903. Values in user9:x:1008:1008::/home/user9:/bin/bash -
  904. user9
  905. x
  906. 1008
  907. 1008
  908.  
  909. /home/user9
  910. /bin/bash
  911. Values in user10:x:1009:1009::/home/user10:/bin/bash -
  912. user10
  913. x
  914. 1009
  915. 1009
  916.  
  917. /home/user10
  918. /bin/bash
  919.  
  920. -----------------------------------------------------------------------------------------
  921.  
  922. user1@lab:~$ nano ./myscript
  923.  
  924. GNU nano 2.5.3 File: ./myscript Modified
  925.  
  926. #!/bin/bash
  927.  
  928. for var1 in 1 2 3 4 5 6 7 8 9 10
  929. do
  930. if [ $var1 -eq 5 ]
  931. then
  932. break
  933. fi
  934. echo "Number: $var1"
  935. done
  936.  
  937. user1@lab:~$ ./myscript
  938. Number: 1
  939. Number: 2
  940. Number: 3
  941. Number: 4
  942.  
  943. -----------------------------------------------------------------------------------------
  944.  
  945. user1@lab:~$ nano ./myscript
  946.  
  947. GNU nano 2.5.3 File: ./myscript Modified
  948.  
  949. #!/bin/bash
  950.  
  951. var1=1
  952.  
  953. while [ $var1 -lt 10 ]
  954. do
  955. if [ $var1 -eq 5 ]
  956. then
  957. break
  958. fi
  959. echo "Iteration: $var1"
  960. var1=$(( $var1 + 1 ))
  961. done
  962.  
  963. user1@lab:~$ ./myscript
  964. Iteration: 1
  965. Iteration: 2
  966. Iteration: 3
  967. Iteration: 4
  968.  
  969. -----------------------------------------------------------------------------------------
  970.  
  971. user1@lab:~$ nano ./myscript
  972.  
  973. GNU nano 2.5.3 File: ./myscript Modified
  974.  
  975. #!/bin/bash
  976.  
  977. for (( var1 = 1; var1 < 15; var1++ ))
  978. do
  979. if [ $var1 -gt 5 ] && [ $var1 -lt 10 ]
  980. then
  981. continue
  982. fi
  983. echo "Iteration number: $var1"
  984. done
  985.  
  986. user1@lab:~$ ./myscript
  987. Iteration number: 1
  988. Iteration number: 2
  989. Iteration number: 3
  990. Iteration number: 4
  991. Iteration number: 5
  992. Iteration number: 10
  993. Iteration number: 11
  994. Iteration number: 12
  995. Iteration number: 13
  996. Iteration number: 14
  997.  
  998. -----------------------------------------------------------------------------------------
  999.  
  1000. user1@lab:~$ nano ./myscript
  1001.  
  1002. GNU nano 2.5.3 File: ./myscript Modified
  1003.  
  1004. #!/bin/bash
  1005.  
  1006. for (( a = 1; a < 10; a++ ))
  1007. do
  1008. echo "Number is $a"
  1009. done > myfile.txt
  1010. echo "finished."
  1011.  
  1012. user1@lab:~$ ./myscript
  1013. finished.
  1014.  
  1015. user1@lab:~$ ls -l
  1016. total 20
  1017. -rw-rw-r-- 1 user1 user1 38 Nov 5 19:15 myfile
  1018. -rw-rw-r-- 1 user1 user1 108 Nov 5 20:22 myfile.txt
  1019. -rwxrwxr-x 1 user1 user1 100 Nov 5 20:21 myscript
  1020. -rw------- 1 user1 user1 2 Oct 27 07:41 nano.save
  1021. -rw-rw-r-- 1 user1 user1 0 Nov 4 18:45 pids
  1022. -rw-rw-r-- 1 user1 user1 0 Oct 20 09:29 test.sh
  1023. -rwxrwxr-x 1 user1 user1 26 Oct 27 07:24 text
  1024.  
  1025. user1@lab:~$ cat myfile.txt
  1026. Number is 1
  1027. Number is 2
  1028. Number is 3
  1029. Number is 4
  1030. Number is 5
  1031. Number is 6
  1032. Number is 7
  1033. Number is 8
  1034. Number is 9
  1035.  
  1036. -----------------------------------------------------------------------------------------
  1037.  
  1038. user1@lab:~$ nano ./myscript
  1039.  
  1040. GNU nano 2.5.3 File: ./myscript Modified
  1041.  
  1042. #!/bin/bash
  1043.  
  1044. IFS=:
  1045.  
  1046. for folder in $PATH
  1047. do
  1048. echo "$folder:"
  1049. for file in $folder/*
  1050. do
  1051. if [ -x $file ]
  1052. then
  1053. echo " $file"
  1054. fi
  1055. done
  1056. done
  1057.  
  1058. user1@lab:~$ ./myscript
  1059. /usr/local/sbin:
  1060. /usr/local/bin:
  1061. /usr/sbin:
  1062. /usr/sbin/aa-exec
  1063. /usr/sbin/aa-status
  1064. /usr/sbin/accessdb
  1065. /usr/sbin/add-shell
  1066. /usr/sbin/addgroup
  1067. /usr/sbin/adduser
  1068. /usr/sbin/apparmor_status
  1069. /usr/sbin/arp
  1070. /usr/sbin/arpd
  1071. /usr/sbin/biosdecode
  1072. /usr/sbin/chgpasswd
  1073. /usr/sbin/chpasswd
  1074. /usr/sbin/chroot
  1075. /usr/sbin/cpgr
  1076. /usr/sbin/cppw
  1077. /usr/sbin/cron
  1078. /usr/sbin/delgroup
  1079. /usr/sbin/deluser
  1080. /usr/sbin/dmidecode
  1081. /usr/sbin/dpkg-divert
  1082. /usr/sbin/dpkg-preconfigure
  1083. /usr/sbin/dpkg-reconfigure
  1084. /usr/sbin/dpkg-statoverride
  1085. /usr/sbin/e2freefrag
  1086. /usr/sbin/e4defrag
  1087. /usr/sbin/fdformat
  1088. /usr/sbin/filefrag
  1089. /usr/sbin/genl
  1090. /usr/sbin/groupadd
  1091. /usr/sbin/groupdel
  1092. /usr/sbin/groupmod
  1093. /usr/sbin/grpck
  1094. /usr/sbin/grpconv
  1095. /usr/sbin/grpunconv
  1096. /usr/sbin/iconvconfig
  1097. /usr/sbin/install-sgmlcatalog
  1098. /usr/sbin/invoke-rc.d
  1099. /usr/sbin/ip6tables-apply
  1100. /usr/sbin/iptables-apply
  1101. /usr/sbin/irqbalance
  1102. /usr/sbin/ldattach
  1103. /usr/sbin/locale-gen
  1104. /usr/sbin/logrotate
  1105. /usr/sbin/make-ssl-cert
  1106. /usr/sbin/mkinitramfs
  1107. /usr/sbin/mklost+found
  1108. /usr/sbin/newusers
  1109. /usr/sbin/nfnl_osf
  1110. /usr/sbin/nologin
  1111. /usr/sbin/ownership
  1112. /usr/sbin/pam-auth-update
  1113. /usr/sbin/pam_getenv
  1114. /usr/sbin/pam_timestamp_check
  1115. /usr/sbin/popcon-largest-unused
  1116. /usr/sbin/popularity-contest
  1117. /usr/sbin/postalias
  1118. /usr/sbin/postcat
  1119. /usr/sbin/postconf
  1120. /usr/sbin/postdrop
  1121. /usr/sbin/postfix
  1122. /usr/sbin/postfix-add-filter
  1123. /usr/sbin/postfix-add-policy
  1124. /usr/sbin/postkick
  1125. /usr/sbin/postlock
  1126. /usr/sbin/postlog
  1127. /usr/sbin/postmap
  1128. /usr/sbin/postmulti
  1129. /usr/sbin/postqueue
  1130. /usr/sbin/postsuper
  1131. /usr/sbin/posttls-finger
  1132. /usr/sbin/pwck
  1133. /usr/sbin/pwconv
  1134. /usr/sbin/pwunconv
  1135. /usr/sbin/qmqp-sink
  1136. /usr/sbin/qmqp-source
  1137. /usr/sbin/qshape
  1138. /usr/sbin/readprofile
  1139. /usr/sbin/remove-shell
  1140. /usr/sbin/rmail
  1141. /usr/sbin/rmt
  1142. /usr/sbin/rmt-tar
  1143. /usr/sbin/rsyslogd
  1144. /usr/sbin/rtcwake
  1145. /usr/sbin/sendmail
  1146. /usr/sbin/service
  1147. /usr/sbin/setvesablank
  1148. /usr/sbin/smtp-sink
  1149. /usr/sbin/smtp-source
  1150. /usr/sbin/sshd
  1151. /usr/sbin/tarcat
  1152. /usr/sbin/tcpdump
  1153. /usr/sbin/tunelp
  1154. /usr/sbin/tzconfig
  1155. /usr/sbin/ufw
  1156. /usr/sbin/update-alternatives
  1157. /usr/sbin/update-ca-certificates
  1158. /usr/sbin/update-catalog
  1159. /usr/sbin/update-info-dir
  1160. /usr/sbin/update-initramfs
  1161. /usr/sbin/update-locale
  1162. /usr/sbin/update-mime
  1163. /usr/sbin/update-passwd
  1164. /usr/sbin/update-pciids
  1165. /usr/sbin/update-rc.d
  1166. /usr/sbin/update-usbids
  1167. /usr/sbin/update-xmlcatalog
  1168. /usr/sbin/useradd
  1169. /usr/sbin/userdel
  1170. /usr/sbin/usermod
  1171. /usr/sbin/uuidd
  1172. /usr/sbin/validlocale
  1173. /usr/sbin/vcstime
  1174. /usr/sbin/vigr
  1175. /usr/sbin/vipw
  1176. /usr/sbin/visudo
  1177. /usr/sbin/vpddecode
  1178. /usr/sbin/zic
  1179. /usr/bin:
  1180. /usr/bin/2to3-3.5
  1181. /usr/bin/X11
  1182. /usr/bin/[
  1183. /usr/bin/aa-enabled
  1184. /usr/bin/addpart
  1185. /usr/bin/appres
  1186. /usr/bin/apropos
  1187. /usr/bin/apt
  1188. /usr/bin/apt-cache
  1189. /usr/bin/apt-cdrom
  1190. /usr/bin/apt-config
  1191. /usr/bin/apt-extracttemplates
  1192. /usr/bin/apt-ftparchive
  1193. /usr/bin/apt-get
  1194. /usr/bin/apt-key
  1195. /usr/bin/apt-mark
  1196. /usr/bin/apt-sortpkgs
  1197. /usr/bin/arch
  1198. /usr/bin/atobm
  1199. /usr/bin/awk
  1200. /usr/bin/base32
  1201. /usr/bin/base64
  1202. /usr/bin/basename
  1203. /usr/bin/bashbug
  1204. /usr/bin/bitmap
  1205. /usr/bin/bmtoa
  1206. /usr/bin/bootctl
  1207. /usr/bin/bsd-from
  1208. /usr/bin/bsd-write
  1209. /usr/bin/busctl
  1210. /usr/bin/c_rehash
  1211. /usr/bin/cal
  1212. /usr/bin/calendar
  1213. /usr/bin/captoinfo
  1214. /usr/bin/catchsegv
  1215. /usr/bin/catman
  1216. /usr/bin/cautious-launcher
  1217. /usr/bin/chage
  1218. /usr/bin/chattr
  1219. /usr/bin/chcon
  1220. /usr/bin/check-language-support
  1221. /usr/bin/chfn
  1222. /usr/bin/chrt
  1223. /usr/bin/chsh
  1224. /usr/bin/ckbcomp
  1225. /usr/bin/cksum
  1226. /usr/bin/clear
  1227. /usr/bin/clear_console
  1228. /usr/bin/cmp
  1229. /usr/bin/codepage
  1230. /usr/bin/col
  1231. /usr/bin/colcrt
  1232. /usr/bin/colrm
  1233. /usr/bin/column
  1234. /usr/bin/comm
  1235. /usr/bin/compose
  1236. /usr/bin/cpp
  1237. /usr/bin/cpp-5
  1238. /usr/bin/crontab
  1239. /usr/bin/csplit
  1240. /usr/bin/ctstat
  1241. /usr/bin/cut
  1242. /usr/bin/dbus-cleanup-sockets
  1243. /usr/bin/dbus-daemon
  1244. /usr/bin/dbus-monitor
  1245. /usr/bin/dbus-run-session
  1246. /usr/bin/dbus-send
  1247. /usr/bin/dbus-update-activation-environment
  1248. /usr/bin/dbus-uuidgen
  1249. /usr/bin/deallocvt
  1250. /usr/bin/deb-systemd-helper
  1251. /usr/bin/deb-systemd-invoke
  1252. /usr/bin/debconf
  1253. /usr/bin/debconf-apt-progress
  1254. /usr/bin/debconf-communicate
  1255. /usr/bin/debconf-copydb
  1256. /usr/bin/debconf-escape
  1257. /usr/bin/debconf-set-selections
  1258. /usr/bin/debconf-show
  1259. /usr/bin/delpart
  1260. /usr/bin/dh_bash-completion
  1261. /usr/bin/dh_installxmlcatalogs
  1262. /usr/bin/dh_pypy
  1263. /usr/bin/dh_python3
  1264. /usr/bin/diff
  1265. /usr/bin/diff3
  1266. /usr/bin/dig
  1267. /usr/bin/dircolors
  1268. /usr/bin/dirname
  1269. /usr/bin/do-release-upgrade
  1270. /usr/bin/dpkg
  1271. /usr/bin/dpkg-deb
  1272. /usr/bin/dpkg-divert
  1273. /usr/bin/dpkg-maintscript-helper
  1274. /usr/bin/dpkg-query
  1275. /usr/bin/dpkg-split
  1276. /usr/bin/dpkg-statoverride
  1277. /usr/bin/dpkg-trigger
  1278. /usr/bin/du
  1279. /usr/bin/dumpkeys
  1280. /usr/bin/edit
  1281. /usr/bin/editor
  1282. /usr/bin/editres
  1283. /usr/bin/eject
  1284. /usr/bin/env
  1285. /usr/bin/envsubst
  1286. /usr/bin/eqn
  1287. /usr/bin/ex
  1288. /usr/bin/expand
  1289. /usr/bin/expiry
  1290. /usr/bin/expr
  1291. /usr/bin/factor
  1292. /usr/bin/faillog
  1293. /usr/bin/fallocate
  1294. /usr/bin/file
  1295. /usr/bin/find
  1296. /usr/bin/flock
  1297. /usr/bin/fmt
  1298. /usr/bin/fold
  1299. /usr/bin/free
  1300. /usr/bin/from
  1301. /usr/bin/ftp
  1302. /usr/bin/geqn
  1303. /usr/bin/getconf
  1304. /usr/bin/getent
  1305. /usr/bin/getkeycodes
  1306. /usr/bin/getopt
  1307. /usr/bin/gettext
  1308. /usr/bin/gettext.sh
  1309. /usr/bin/ginstall-info
  1310. /usr/bin/gpasswd
  1311. /usr/bin/gpg
  1312. /usr/bin/gpg-zip
  1313. /usr/bin/gpgsplit
  1314. /usr/bin/gpgv
  1315. /usr/bin/gpic
  1316. /usr/bin/groff
  1317. /usr/bin/grog
  1318. /usr/bin/grops
  1319. /usr/bin/grotty
  1320. /usr/bin/groups
  1321. /usr/bin/gtbl
  1322. /usr/bin/hd
  1323. /usr/bin/head
  1324. /usr/bin/helpztags
  1325. /usr/bin/hexdump
  1326. /usr/bin/host
  1327. /usr/bin/hostid
  1328. /usr/bin/hostnamectl
  1329. /usr/bin/i386
  1330. /usr/bin/iceauth
  1331. /usr/bin/ico
  1332. /usr/bin/iconv
  1333. /usr/bin/id
  1334. /usr/bin/info
  1335. /usr/bin/infobrowser
  1336. /usr/bin/infocmp
  1337. /usr/bin/infotocap
  1338. /usr/bin/install
  1339. /usr/bin/install-info
  1340. /usr/bin/ionice
  1341. /usr/bin/ipcmk
  1342. /usr/bin/ipcrm
  1343. /usr/bin/ipcs
  1344. /usr/bin/iptables-xml
  1345. /usr/bin/ischroot
  1346. /usr/bin/join
  1347. /usr/bin/kbdinfo
  1348. /usr/bin/killall
  1349. /usr/bin/last
  1350. /usr/bin/lastb
  1351. /usr/bin/lastlog
  1352. /usr/bin/lcf
  1353. /usr/bin/ldd
  1354. /usr/bin/less
  1355. /usr/bin/lessecho
  1356. /usr/bin/lessfile
  1357. /usr/bin/lesskey
  1358. /usr/bin/lesspipe
  1359. /usr/bin/lexgrog
  1360. /usr/bin/line
  1361. /usr/bin/link
  1362. /usr/bin/linux-version
  1363. /usr/bin/linux32
  1364. /usr/bin/linux64
  1365. /usr/bin/listres
  1366. /usr/bin/lnstat
  1367. /usr/bin/loadkeys
  1368. /usr/bin/loadunimap
  1369. /usr/bin/locale
  1370. /usr/bin/localectl
  1371. /usr/bin/localedef
  1372. /usr/bin/locate
  1373. /usr/bin/logger
  1374. /usr/bin/logname
  1375. /usr/bin/look
  1376. /usr/bin/lorder
  1377. /usr/bin/lsattr
  1378. /usr/bin/lsb_release
  1379. /usr/bin/lscpu
  1380. /usr/bin/lshw
  1381. /usr/bin/lsinitramfs
  1382. /usr/bin/lsipc
  1383. /usr/bin/lslocks
  1384. /usr/bin/lslogins
  1385. /usr/bin/lsof
  1386. /usr/bin/lspci
  1387. /usr/bin/lspgpot
  1388. /usr/bin/lsusb
  1389. /usr/bin/ltrace
  1390. /usr/bin/luit
  1391. /usr/bin/mailq
  1392. /usr/bin/man
  1393. /usr/bin/mandb
  1394. /usr/bin/manpath
  1395. /usr/bin/mapscrn
  1396. /usr/bin/mawk
  1397. /usr/bin/mcookie
  1398. /usr/bin/md5sum
  1399. /usr/bin/md5sum.textutils
  1400. /usr/bin/mesg
  1401. /usr/bin/mk_modmap
  1402. /usr/bin/mkfifo
  1403. /usr/bin/mlocate
  1404. /usr/bin/mtr
  1405. /usr/bin/namei
  1406. /usr/bin/nawk
  1407. /usr/bin/ncal
  1408. /usr/bin/neqn
  1409. /usr/bin/netkit-ftp
  1410. /usr/bin/newaliases
  1411. /usr/bin/newgrp
  1412. /usr/bin/ngettext
  1413. /usr/bin/nice
  1414. /usr/bin/nl
  1415. /usr/bin/nohup
  1416. /usr/bin/nproc
  1417. /usr/bin/nroff
  1418. /usr/bin/nsenter
  1419. /usr/bin/nslookup
  1420. /usr/bin/nstat
  1421. /usr/bin/nsupdate
  1422. /usr/bin/ntfsdecrypt
  1423. /usr/bin/numfmt
  1424. /usr/bin/oclock
  1425. /usr/bin/od
  1426. /usr/bin/on_ac_power
  1427. /usr/bin/openssl
  1428. /usr/bin/pager
  1429. /usr/bin/partx
  1430. /usr/bin/passwd
  1431. /usr/bin/paste
  1432. /usr/bin/pathchk
  1433. /usr/bin/pcimodules
  1434. /usr/bin/pdb3
  1435. /usr/bin/pdb3.5
  1436. /usr/bin/peekfd
  1437. /usr/bin/perl
  1438. /usr/bin/perl5.22.1
  1439. /usr/bin/pftp
  1440. /usr/bin/pg
  1441. /usr/bin/pgrep
  1442. /usr/bin/pic
  1443. /usr/bin/pico
  1444. /usr/bin/pinky
  1445. /usr/bin/pkill
  1446. /usr/bin/pldd
  1447. /usr/bin/pmap
  1448. /usr/bin/pr
  1449. /usr/bin/preconv
  1450. /usr/bin/print
  1451. /usr/bin/printenv
  1452. /usr/bin/printerbanner
  1453. /usr/bin/printf
  1454. /usr/bin/prlimit
  1455. /usr/bin/prtstat
  1456. /usr/bin/psfaddtable
  1457. /usr/bin/psfgettable
  1458. /usr/bin/psfstriptable
  1459. /usr/bin/psfxtable
  1460. /usr/bin/pstree
  1461. /usr/bin/pstree.x11
  1462. /usr/bin/ptx
  1463. /usr/bin/pwdx
  1464. /usr/bin/py3clean
  1465. /usr/bin/py3compile
  1466. /usr/bin/py3versions
  1467. /usr/bin/pybuild
  1468. /usr/bin/pydoc3
  1469. /usr/bin/pydoc3.5
  1470. /usr/bin/pygettext3
  1471. /usr/bin/pygettext3.5
  1472. /usr/bin/python3
  1473. /usr/bin/python3.5
  1474. /usr/bin/python3.5m
  1475. /usr/bin/python3m
  1476. /usr/bin/rcp
  1477. /usr/bin/realpath
  1478. /usr/bin/rename.ul
  1479. /usr/bin/rendercheck
  1480. /usr/bin/renice
  1481. /usr/bin/reset
  1482. /usr/bin/resizecons
  1483. /usr/bin/resizepart
  1484. /usr/bin/rev
  1485. /usr/bin/rgrep
  1486. /usr/bin/rlogin
  1487. /usr/bin/rmail
  1488. /usr/bin/routef
  1489. /usr/bin/routel
  1490. /usr/bin/rsh
  1491. /usr/bin/rstart
  1492. /usr/bin/rstartd
  1493. /usr/bin/rsync
  1494. /usr/bin/rtstat
  1495. /usr/bin/run-mailcap
  1496. /usr/bin/runcon
  1497. /usr/bin/rview
  1498. /usr/bin/rvim
  1499. /usr/bin/savelog
  1500. /usr/bin/scp
  1501. /usr/bin/screendump
  1502. /usr/bin/script
  1503. /usr/bin/scriptreplay
  1504. /usr/bin/sdiff
  1505. /usr/bin/see
  1506. /usr/bin/select-editor
  1507. /usr/bin/sensible-browser
  1508. /usr/bin/sensible-editor
  1509. /usr/bin/sensible-pager
  1510. /usr/bin/seq
  1511. /usr/bin/sessreg
  1512. /usr/bin/setarch
  1513. /usr/bin/setkeycodes
  1514. /usr/bin/setleds
  1515. /usr/bin/setlogcons
  1516. /usr/bin/setmetamode
  1517. /usr/bin/setpci
  1518. /usr/bin/setsid
  1519. /usr/bin/setterm
  1520. /usr/bin/setxkbmap
  1521. /usr/bin/sftp
  1522. /usr/bin/sg
  1523. /usr/bin/sha1sum
  1524. /usr/bin/sha224sum
  1525. /usr/bin/sha256sum
  1526. /usr/bin/sha384sum
  1527. /usr/bin/sha512sum
  1528. /usr/bin/showconsolefont
  1529. /usr/bin/showkey
  1530. /usr/bin/showrgb
  1531. /usr/bin/shred
  1532. /usr/bin/shuf
  1533. /usr/bin/skill
  1534. /usr/bin/slabtop
  1535. /usr/bin/slogin
  1536. /usr/bin/smproxy
  1537. /usr/bin/snice
  1538. /usr/bin/soelim
  1539. /usr/bin/sort
  1540. /usr/bin/split
  1541. /usr/bin/splitfont
  1542. /usr/bin/ssh
  1543. /usr/bin/ssh-add
  1544. /usr/bin/ssh-agent
  1545. /usr/bin/ssh-argv0
  1546. /usr/bin/ssh-copy-id
  1547. /usr/bin/ssh-keygen
  1548. /usr/bin/ssh-keyscan
  1549. /usr/bin/startx
  1550. /usr/bin/stat
  1551. /usr/bin/stdbuf
  1552. /usr/bin/strace
  1553. /usr/bin/sudo
  1554. /usr/bin/sudoedit
  1555. /usr/bin/sudoreplay
  1556. /usr/bin/sum
  1557. /usr/bin/systemd-analyze
  1558. /usr/bin/systemd-cat
  1559. /usr/bin/systemd-cgls
  1560. /usr/bin/systemd-cgtop
  1561. /usr/bin/systemd-delta
  1562. /usr/bin/systemd-detect-virt
  1563. /usr/bin/systemd-path
  1564. /usr/bin/systemd-resolve
  1565. /usr/bin/systemd-run
  1566. /usr/bin/systemd-stdio-bridge
  1567. /usr/bin/tabs
  1568. /usr/bin/tac
  1569. /usr/bin/tail
  1570. /usr/bin/taskset
  1571. /usr/bin/tbl
  1572. /usr/bin/tee
  1573. /usr/bin/telnet
  1574. /usr/bin/telnet.netkit
  1575. /usr/bin/test
  1576. /usr/bin/tic
  1577. /usr/bin/time
  1578. /usr/bin/timedatectl
  1579. /usr/bin/timeout
  1580. /usr/bin/tload
  1581. /usr/bin/toe
  1582. /usr/bin/top
  1583. /usr/bin/touch
  1584. /usr/bin/tput
  1585. /usr/bin/tr
  1586. /usr/bin/tracepath
  1587. /usr/bin/tracepath6
  1588. /usr/bin/traceroute6
  1589. /usr/bin/traceroute6.iputils
  1590. /usr/bin/transset
  1591. /usr/bin/troff
  1592. /usr/bin/truncate
  1593. /usr/bin/tset
  1594. /usr/bin/tsort
  1595. /usr/bin/tty
  1596. /usr/bin/tzselect
  1597. /usr/bin/ubuntu-support-status
  1598. /usr/bin/ucf
  1599. /usr/bin/ucfq
  1600. /usr/bin/ucfr
  1601. /usr/bin/ul
  1602. /usr/bin/unexpand
  1603. /usr/bin/unicode_stop
  1604. /usr/bin/uniq
  1605. /usr/bin/unlink
  1606. /usr/bin/unshare
  1607. /usr/bin/update-alternatives
  1608. /usr/bin/update-mime-database
  1609. /usr/bin/update-mime-database.real
  1610. /usr/bin/updatedb
  1611. /usr/bin/updatedb.mlocate
  1612. /usr/bin/uptime
  1613. /usr/bin/usb-devices
  1614. /usr/bin/usbhid-dump
  1615. /usr/bin/users
  1616. /usr/bin/utmpdump
  1617. /usr/bin/uuidgen
  1618. /usr/bin/vi
  1619. /usr/bin/view
  1620. /usr/bin/viewres
  1621. /usr/bin/vim
  1622. /usr/bin/vim.basic
  1623. /usr/bin/vim.tiny
  1624. /usr/bin/vimdiff
  1625. /usr/bin/vimtutor
  1626. /usr/bin/vmstat
  1627. /usr/bin/volname
  1628. /usr/bin/w
  1629. /usr/bin/w.procps
  1630. /usr/bin/wall
  1631. /usr/bin/watch
  1632. /usr/bin/wc
  1633. /usr/bin/wget
  1634. /usr/bin/whatis
  1635. /usr/bin/whereis
  1636. /usr/bin/which
  1637. /usr/bin/who
  1638. /usr/bin/whoami
  1639. /usr/bin/write
  1640. /usr/bin/x11perf
  1641. /usr/bin/x11perfcomp
  1642. /usr/bin/x86_64
  1643. /usr/bin/x86_64-linux-gnu-cpp
  1644. /usr/bin/x86_64-linux-gnu-cpp-5
  1645. /usr/bin/xargs
  1646. /usr/bin/xauth
  1647. /usr/bin/xbiff
  1648. /usr/bin/xcalc
  1649. /usr/bin/xclipboard
  1650. /usr/bin/xclock
  1651. /usr/bin/xcmsdb
  1652. /usr/bin/xconsole
  1653. /usr/bin/xcursorgen
  1654. /usr/bin/xcutsel
  1655. /usr/bin/xdg-user-dir
  1656. /usr/bin/xdg-user-dirs-update
  1657. /usr/bin/xditview
  1658. /usr/bin/xdpyinfo
  1659. /usr/bin/xdriinfo
  1660. /usr/bin/xedit
  1661. /usr/bin/xev
  1662. /usr/bin/xeyes
  1663. /usr/bin/xfd
  1664. /usr/bin/xfontsel
  1665. /usr/bin/xgamma
  1666. /usr/bin/xgc
  1667. /usr/bin/xhost
  1668. /usr/bin/xinit
  1669. /usr/bin/xkbbell
  1670. /usr/bin/xkbcomp
  1671. /usr/bin/xkbevd
  1672. /usr/bin/xkbprint
  1673. /usr/bin/xkbvleds
  1674. /usr/bin/xkbwatch
  1675. /usr/bin/xkeystone
  1676. /usr/bin/xkill
  1677. /usr/bin/xload
  1678. /usr/bin/xlogo
  1679. /usr/bin/xlsatoms
  1680. /usr/bin/xlsclients
  1681. /usr/bin/xlsfonts
  1682. /usr/bin/xmag
  1683. /usr/bin/xman
  1684. /usr/bin/xmessage
  1685. /usr/bin/xmodmap
  1686. /usr/bin/xmore
  1687. /usr/bin/xprop
  1688. /usr/bin/xrandr
  1689. /usr/bin/xrdb
  1690. /usr/bin/xrefresh
  1691. /usr/bin/xset
  1692. /usr/bin/xsetmode
  1693. /usr/bin/xsetpointer
  1694. /usr/bin/xsetroot
  1695. /usr/bin/xsm
  1696. /usr/bin/xstdcmap
  1697. /usr/bin/xvidtune
  1698. /usr/bin/xvinfo
  1699. /usr/bin/xwd
  1700. /usr/bin/xwininfo
  1701. /usr/bin/xwud
  1702. /usr/bin/xxd
  1703. /usr/bin/yes
  1704. /usr/bin/zdump
  1705. /sbin:
  1706. /sbin/MAKEDEV
  1707. /sbin/acpi_available
  1708. /sbin/agetty
  1709. /sbin/apm_available
  1710. /sbin/apparmor_parser
  1711. /sbin/badblocks
  1712. /sbin/blkdiscard
  1713. /sbin/blkid
  1714. /sbin/blockdev
  1715. /sbin/bridge
  1716. /sbin/capsh
  1717. /sbin/cfdisk
  1718. /sbin/chcpu
  1719. /sbin/ctrlaltdel
  1720. /sbin/debugfs
  1721. /sbin/depmod
  1722. /sbin/dhclient
  1723. /sbin/dhclient-script
  1724. /sbin/dosfsck
  1725. /sbin/dosfslabel
  1726. /sbin/dumpe2fs
  1727. /sbin/e2fsck
  1728. /sbin/e2image
  1729. /sbin/e2label
  1730. /sbin/e2undo
  1731. /sbin/fatlabel
  1732. /sbin/fdisk
  1733. /sbin/findfs
  1734. /sbin/fsck
  1735. /sbin/fsck.cramfs
  1736. /sbin/fsck.ext2
  1737. /sbin/fsck.ext3
  1738. /sbin/fsck.ext4
  1739. /sbin/fsck.ext4dev
  1740. /sbin/fsck.fat
  1741. /sbin/fsck.minix
  1742. /sbin/fsck.msdos
  1743. /sbin/fsck.nfs
  1744. /sbin/fsck.vfat
  1745. /sbin/fsfreeze
  1746. /sbin/fstab-decode
  1747. /sbin/fstrim
  1748. /sbin/getcap
  1749. /sbin/getpcaps
  1750. /sbin/getty
  1751. /sbin/halt
  1752. /sbin/hdparm
  1753. /sbin/hwclock
  1754. /sbin/ifconfig
  1755. /sbin/ifdown
  1756. /sbin/ifquery
  1757. /sbin/ifup
  1758. /sbin/init
  1759. /sbin/insmod
  1760. /sbin/installkernel
  1761. /sbin/ip
  1762. /sbin/ip6tables
  1763. /sbin/ip6tables-restore
  1764. /sbin/ip6tables-save
  1765. /sbin/ipmaddr
  1766. /sbin/iptables
  1767. /sbin/iptables-restore
  1768. /sbin/iptables-save
  1769. /sbin/iptunnel
  1770. /sbin/isosize
  1771. /sbin/kbdrate
  1772. /sbin/killall5
  1773. /sbin/ldconfig
  1774. /sbin/ldconfig.real
  1775. /sbin/logsave
  1776. /sbin/losetup
  1777. /sbin/lsmod
  1778. /sbin/mii-tool
  1779. /sbin/mkdosfs
  1780. /sbin/mke2fs
  1781. /sbin/mkfs
  1782. /sbin/mkfs.bfs
  1783. /sbin/mkfs.cramfs
  1784. /sbin/mkfs.ext2
  1785. /sbin/mkfs.ext3
  1786. /sbin/mkfs.ext4
  1787. /sbin/mkfs.ext4dev
  1788. /sbin/mkfs.fat
  1789. /sbin/mkfs.minix
  1790. /sbin/mkfs.msdos
  1791. /sbin/mkfs.ntfs
  1792. /sbin/mkfs.vfat
  1793. /sbin/mkhomedir_helper
  1794. /sbin/mkntfs
  1795. /sbin/mkswap
  1796. /sbin/modinfo
  1797. /sbin/modprobe
  1798. /sbin/mount.fuse
  1799. /sbin/mount.lowntfs-3g
  1800. /sbin/mount.ntfs
  1801. /sbin/mount.ntfs-3g
  1802. /sbin/nameif
  1803. /sbin/ntfsclone
  1804. /sbin/ntfscp
  1805. /sbin/ntfslabel
  1806. /sbin/ntfsresize
  1807. /sbin/ntfsundelete
  1808. /sbin/on_ac_power
  1809. /sbin/pam_extrausers_chkpwd
  1810. /sbin/pam_extrausers_update
  1811. /sbin/pam_tally
  1812. /sbin/pam_tally2
  1813. /sbin/parted
  1814. /sbin/partprobe
  1815. /sbin/pivot_root
  1816. /sbin/plipconfig
  1817. /sbin/plymouthd
  1818. /sbin/poweroff
  1819. /sbin/rarp
  1820. /sbin/raw
  1821. /sbin/reboot
  1822. /sbin/resize2fs
  1823. /sbin/resolvconf
  1824. /sbin/rmmod
  1825. /sbin/route
  1826. /sbin/rtacct
  1827. /sbin/rtmon
  1828. /sbin/runlevel
  1829. /sbin/runuser
  1830. /sbin/setcap
  1831. /sbin/setvtrgb
  1832. /sbin/sfdisk
  1833. /sbin/shadowconfig
  1834. /sbin/shutdown
  1835. /sbin/slattach
  1836. /sbin/start-stop-daemon
  1837. /sbin/sulogin
  1838. /sbin/swaplabel
  1839. /sbin/swapoff
  1840. /sbin/swapon
  1841. /sbin/switch_root
  1842. /sbin/sysctl
  1843. /sbin/tc
  1844. /sbin/telinit
  1845. /sbin/tipc
  1846. /sbin/tune2fs
  1847. /sbin/udevadm
  1848. /sbin/unix_chkpwd
  1849. /sbin/unix_update
  1850. /sbin/ureadahead
  1851. /sbin/wipefs
  1852. /sbin/xtables-multi
  1853. /sbin/zramctl
  1854. /bin:
  1855. /bin/bash
  1856. /bin/bunzip2
  1857. /bin/busybox
  1858. /bin/bzcat
  1859. /bin/bzcmp
  1860. /bin/bzdiff
  1861. /bin/bzegrep
  1862. /bin/bzexe
  1863. /bin/bzfgrep
  1864. /bin/bzgrep
  1865. /bin/bzip2
  1866. /bin/bzip2recover
  1867. /bin/bzless
  1868. /bin/bzmore
  1869. /bin/cat
  1870. /bin/chgrp
  1871. /bin/chmod
  1872. /bin/chown
  1873. /bin/chvt
  1874. /bin/cp
  1875. /bin/cpio
  1876. /bin/dash
  1877. /bin/date
  1878. /bin/dd
  1879. /bin/df
  1880. /bin/dir
  1881. /bin/dmesg
  1882. /bin/dnsdomainname
  1883. /bin/domainname
  1884. /bin/dumpkeys
  1885. /bin/echo
  1886. /bin/ed
  1887. /bin/egrep
  1888. /bin/false
  1889. /bin/fgconsole
  1890. /bin/fgrep
  1891. /bin/findmnt
  1892. /bin/fuser
  1893. /bin/fusermount
  1894. /bin/grep
  1895. /bin/gunzip
  1896. /bin/gzexe
  1897. /bin/gzip
  1898. /bin/hostname
  1899. /bin/ip
  1900. /bin/journalctl
  1901. /bin/kbd_mode
  1902. /bin/kill
  1903. /bin/kmod
  1904. /bin/less
  1905. /bin/lessecho
  1906. /bin/lessfile
  1907. /bin/lesskey
  1908. /bin/lesspipe
  1909. /bin/ln
  1910. /bin/loadkeys
  1911. /bin/login
  1912. /bin/loginctl
  1913. /bin/lowntfs-3g
  1914. /bin/ls
  1915. /bin/lsblk
  1916. /bin/lsmod
  1917. /bin/mkdir
  1918. /bin/mknod
  1919. /bin/mktemp
  1920. /bin/more
  1921. /bin/mount
  1922. /bin/mountpoint
  1923. /bin/mt
  1924. /bin/mt-gnu
  1925. /bin/mv
  1926. /bin/nano
  1927. /bin/nc
  1928. /bin/nc.openbsd
  1929. /bin/netcat
  1930. /bin/netstat
  1931. /bin/networkctl
  1932. /bin/nisdomainname
  1933. /bin/ntfs-3g
  1934. /bin/ntfs-3g.probe
  1935. /bin/ntfs-3g.secaudit
  1936. /bin/ntfs-3g.usermap
  1937. /bin/ntfscat
  1938. /bin/ntfscluster
  1939. /bin/ntfscmp
  1940. /bin/ntfsfallocate
  1941. /bin/ntfsfix
  1942. /bin/ntfsinfo
  1943. /bin/ntfsls
  1944. /bin/ntfsmove
  1945. /bin/ntfstruncate
  1946. /bin/ntfswipe
  1947. /bin/open
  1948. /bin/openvt
  1949. /bin/pidof
  1950. /bin/ping
  1951. /bin/ping6
  1952. /bin/plymouth
  1953. /bin/ps
  1954. /bin/pwd
  1955. /bin/rbash
  1956. /bin/readlink
  1957. /bin/red
  1958. /bin/rm
  1959. /bin/rmdir
  1960. /bin/rnano
  1961. /bin/run-parts
  1962. /bin/sed
  1963. /bin/setfont
  1964. /bin/setupcon
  1965. /bin/sh
  1966. /bin/sh.distrib
  1967. /bin/sleep
  1968. /bin/ss
  1969. /bin/static-sh
  1970. /bin/stty
  1971. /bin/su
  1972. /bin/sync
  1973. /bin/systemctl
  1974. /bin/systemd
  1975. /bin/systemd-ask-password
  1976. /bin/systemd-escape
  1977. /bin/systemd-hwdb
  1978. /bin/systemd-inhibit
  1979. /bin/systemd-machine-id-setup
  1980. /bin/systemd-notify
  1981. /bin/systemd-tmpfiles
  1982. /bin/systemd-tty-ask-password-agent
  1983. /bin/tailf
  1984. /bin/tar
  1985. /bin/tempfile
  1986. /bin/touch
  1987. /bin/true
  1988. /bin/udevadm
  1989. /bin/ulockmgr_server
  1990. /bin/umount
  1991. /bin/uname
  1992. /bin/uncompress
  1993. /bin/unicode_start
  1994. /bin/vdir
  1995. /bin/wdctl
  1996. /bin/which
  1997. /bin/whiptail
  1998. /bin/ypdomainname
  1999. /bin/zcat
  2000. /bin/zcmp
  2001. /bin/zdiff
  2002. /bin/zegrep
  2003. /bin/zfgrep
  2004. /bin/zforce
  2005. /bin/zgrep
  2006. /bin/zless
  2007. /bin/zmore
  2008. /bin/znew
  2009. /usr/games:
  2010. /usr/local/games:
  2011.  
  2012. -----------------------------------------------------------------------------------------
  2013.  
  2014. user1@lab:~$ nano ./myscript
  2015.  
  2016. GNU nano 2.5.3 File: ./myscript Modified
  2017.  
  2018. #!/bin/bash
  2019.  
  2020. echo $0
  2021. echo $1
  2022. echo $2
  2023. echo $3
  2024.  
  2025. user1@lab:~$ ./myscript 5 10 15
  2026. ./myscript
  2027. 5
  2028. 10
  2029. 15
  2030.  
  2031. user1@lab:~$ ./myscript 7 15 -1
  2032. ./myscript
  2033. 7
  2034. 15
  2035. -1
  2036.  
  2037. -----------------------------------------------------------------------------------------
  2038.  
  2039. user1@lab:~$ nano ./myscript
  2040.  
  2041. GNU nano 2.5.3 File: ./myscript Modified
  2042.  
  2043. #!/bin/bash
  2044.  
  2045. total=$[ $1 + $2 ]
  2046. echo The first parameter is $1.
  2047. echo The second parameter is $2.
  2048. echo The sum is $total.
  2049.  
  2050. user1@lab:~$ ./myscript 5 10 15
  2051. The first parameter is 5.
  2052. The second parameter is 10.
  2053. The sum is 15.
  2054.  
  2055. user1@lab:~$ ./myscript 20 40 34
  2056. The first parameter is 20.
  2057. The second parameter is 40.
  2058. The sum is 60.
  2059.  
  2060. -----------------------------------------------------------------------------------------
  2061.  
  2062. user1@lab:~$ nano ./myscript
  2063.  
  2064. GNU nano 2.5.3 File: ./myscript Modified
  2065.  
  2066. #!/bin/bash
  2067.  
  2068. echo Hello $1, how do you do
  2069.  
  2070. user1@lab:~$ ./myscript Adam
  2071. Hello Adam, how do you do
  2072.  
  2073. user1@lab:~$ ./myscript John
  2074. Hello John, how do you do
  2075.  
  2076. -----------------------------------------------------------------------------------------
  2077.  
  2078. user1@lab:~$ nano ./myscript
  2079.  
  2080. GNU nano 2.5.3 File: ./myscript Modified
  2081.  
  2082. #!/bin/bash
  2083.  
  2084. if [ -n "$1" ]
  2085. then
  2086. echo Hello $1.
  2087. else
  2088. echo "No parameters found."
  2089. fi
  2090.  
  2091. user1@lab:~$ ./myscript John
  2092. Hello John.
  2093.  
  2094. user1@lab:~$ ./myscript
  2095. No parameters found.
  2096.  
  2097. -----------------------------------------------------------------------------------------
  2098.  
  2099. user1@lab:~$ nano ./myscript
  2100.  
  2101. GNU nano 2.5.3 File: ./myscript Modified
  2102.  
  2103. #!/bin/bash
  2104.  
  2105. echo There were $# parameters passed.
  2106.  
  2107. user1@lab:~$ ./myscript 1 2 3 4 5
  2108. There were 5 parameters passed.
  2109.  
  2110. user1@lab:~$ ./myscript 7 5 3 2 1 10 8 -1
  2111. There were 8 parameters passed.
  2112.  
  2113. -----------------------------------------------------------------------------------------
  2114.  
  2115. user1@lab:~$ nano ./myscript
  2116.  
  2117. GNU nano 2.5.3 File: ./myscript Modified
  2118.  
  2119. #!/bin/bash
  2120.  
  2121. echo The last parameter was ${!#}
  2122.  
  2123. user1@lab:~$ ./myscript 1 2 3 4 5
  2124. The last parameter was 5
  2125.  
  2126. user1@lab:~$ ./myscript 7 5 3 2 1 10 8 -1
  2127. The last parameter was -1
  2128.  
  2129. -----------------------------------------------------------------------------------------
  2130.  
  2131. user1@lab:~$ nano ./myscript
  2132.  
  2133. GNU nano 2.5.3 File: ./myscript Modified
  2134.  
  2135. #!/bin/bash
  2136.  
  2137. echo "Using the \$* method: $*"
  2138. echo "-----------"
  2139. echo "Using the \$@ method: $@"
  2140.  
  2141. user1@lab:~$ ./myscript 1 2 3 4 5
  2142. Using the $* method: 1 2 3 4 5
  2143. -----------
  2144. Using the $@ method: 1 2 3 4 5
  2145.  
  2146. user1@lab:~$ ./myscript 7 5 3 2 1 10 8 -1
  2147. Using the $* method: 7 5 3 2 1 10 8 -1
  2148. -----------
  2149. Using the $@ method: 7 5 3 2 1 10 8 -1
  2150.  
  2151. -----------------------------------------------------------------------------------------
  2152.  
  2153. user1@lab:~$ nano ./myscript
  2154.  
  2155. GNU nano 2.5.3 File: ./myscript Modified
  2156.  
  2157. #!/bin/bash
  2158.  
  2159. count=1
  2160.  
  2161. for param in "$*"
  2162. do
  2163. echo "\$* Parameter #$count = $param"
  2164. count=$(( $count + 1 ))
  2165. done
  2166.  
  2167. count=1
  2168.  
  2169. for param in "$@"
  2170. do
  2171. echo "\$@ Parameter #$count = $param"
  2172. count=$(( $count + 1 ))
  2173. done
  2174.  
  2175. user1@lab:~$ ./myscript 1 2 3 4 5
  2176. $* Parameter #1 = 1 2 3 4 5
  2177. $@ Parameter #1 = 1
  2178. $@ Parameter #2 = 2
  2179. $@ Parameter #3 = 3
  2180. $@ Parameter #4 = 4
  2181. $@ Parameter #5 = 5
  2182.  
  2183. user1@lab:~$ ./myscript 7 5 3 2 1 10 8 -1
  2184. $* Parameter #1 = 7 5 3 2 1 10 8 -1
  2185. $@ Parameter #1 = 7
  2186. $@ Parameter #2 = 5
  2187. $@ Parameter #3 = 3
  2188. $@ Parameter #4 = 2
  2189. $@ Parameter #5 = 1
  2190. $@ Parameter #6 = 10
  2191. $@ Parameter #7 = 8
  2192. $@ Parameter #8 = -1
  2193.  
  2194. -----------------------------------------------------------------------------------------
  2195.  
  2196. user1@lab:~$ nano ./myscript
  2197.  
  2198. GNU nano 2.5.3 File: ./myscript Modified
  2199.  
  2200. #!/bin/bash
  2201.  
  2202. count=1
  2203.  
  2204. while [ -n "$1" ]
  2205. do
  2206. echo "Parameter #$count = $1"
  2207. count=$(( $count + 1 ))
  2208. shift
  2209. done
  2210.  
  2211. user1@lab:~$ ./myscript 1 2 3 4 5
  2212. Parameter #1 = 1
  2213. Parameter #2 = 2
  2214. Parameter #3 = 3
  2215. Parameter #4 = 4
  2216. Parameter #5 = 5
  2217.  
  2218. user1@lab:~$ ./myscript 7 5 3 2 1 10 8 -1
  2219. Parameter #1 = 7
  2220. Parameter #2 = 5
  2221. Parameter #3 = 3
  2222. Parameter #4 = 2
  2223. Parameter #5 = 1
  2224. Parameter #6 = 10
  2225. Parameter #7 = 8
  2226. Parameter #8 = -1
  2227.  
  2228. -----------------------------------------------------------------------------------------
  2229.  
  2230. user1@lab:~$ nano ./myscript
  2231.  
  2232. GNU nano 2.5.3 File: ./myscript Modified
  2233.  
  2234. #!/bin/bash
  2235.  
  2236. echo
  2237. while [ -n "$1" ]
  2238. do
  2239. case "$1" in
  2240. -a) echo "Found the -a option" ;;
  2241. -b) echo "Found the -b option" ;;
  2242. -c) echo "Found the -c option" ;;
  2243. *) echo "$1 is not an option" ;;
  2244. esac
  2245. shift
  2246. done
  2247.  
  2248. user1@lab:~$ ./myscript -a -b -c -d -1 2 @
  2249.  
  2250. Found the -a option
  2251. Found the -b option
  2252. Found the -c option
  2253. -d is not an option
  2254. -1 is not an option
  2255. 2 is not an option
  2256. @ is not an option
  2257.  
  2258. -----------------------------------------------------------------------------------------
  2259.  
  2260. user1@lab:~$ nano ./myscript
  2261.  
  2262. GNU nano 2.5.3 File: ./myscript Modified
  2263.  
  2264. #!/bin/bash
  2265.  
  2266. while [ -n "$1" ]
  2267. do
  2268. case "$1" in
  2269. -a) echo "Found the -a option" ;;
  2270. -b) echo "Found the -b option";;
  2271. -c) echo "Found the -c option" ;;
  2272. --) shift
  2273. break ;;
  2274. *) echo "$1 is not an option";;
  2275. esac
  2276. shift
  2277. done
  2278.  
  2279. count=1
  2280.  
  2281. for param in $@
  2282. do
  2283. echo "Parameter #$count: $param"
  2284. count=$(( $count + 1 ))
  2285. done
  2286.  
  2287. user1@lab:~$ ./myscript -a -b -c 1 ! -3 -- 7 25 -12 -33
  2288. Found the -a option
  2289. Found the -b option
  2290. Found the -c option
  2291. 1 is not an option
  2292. ! is not an option
  2293. -3 is not an option
  2294. Parameter #1: 7
  2295. Parameter #2: 25
  2296. Parameter #3: -12
  2297. Parameter #4: -33
  2298.  
  2299. -----------------------------------------------------------------------------------------
  2300.  
  2301. user1@lab:~$ nano ./myscript
  2302.  
  2303. GNU nano 2.5.3 File: ./myscript Modified
  2304.  
  2305. #!/bin/bash
  2306.  
  2307. while [ -n "$1" ]
  2308. do
  2309. case "$1" in
  2310. -a) echo "Found the -a option";;
  2311. -b) param="$2"
  2312. echo "Found the -b option, with parameter value $param"
  2313. shift ;;
  2314. -c) echo "Found the -c option";;
  2315. --) shift
  2316. break ;;
  2317. *) echo "$1 is not an option";;
  2318. esac
  2319. shift
  2320. done
  2321.  
  2322. count=1
  2323.  
  2324. for param in "$@"
  2325. do
  2326. echo "Parameter #$count: $param"
  2327. count=$(( $count + 1 ))
  2328. done
  2329.  
  2330. user1@lab:~$ ./myscript -a -b 20 -c 'test' -- 12 14 44
  2331. Found the -a option
  2332. Found the -b option, with parameter value 20
  2333. Found the -c option
  2334. test is not an option
  2335. Parameter #1: 12
  2336. Parameter #2: 14
  2337. Parameter #3: 44
  2338.  
  2339. -----------------------------------------------------------------------------------------
  2340.  
  2341. user1@lab:~$ nano ./myscript
  2342.  
  2343. GNU nano 2.5.3 File: ./myscript Modified
  2344.  
  2345. #!/bin/bash
  2346.  
  2347. echo -n "Enter your name: "
  2348. read name
  2349. echo "Hello $name, welcome to my program."
  2350.  
  2351. user1@lab:~$ ./myscript
  2352. Enter your name: Adam
  2353. Hello Adam, welcome to my program.
  2354.  
  2355. -----------------------------------------------------------------------------------------
  2356.  
  2357. user1@lab:~$ nano ./myscript
  2358.  
  2359. GNU nano 2.5.3 File: ./myscript Modified
  2360.  
  2361. #!/bin/bash
  2362.  
  2363. read -p "Enter your name: " first last
  2364. echo "Your data for $last, $first..."
  2365.  
  2366. user1@lab:~$ ./myscript
  2367. Enter your name: first last
  2368. Your data for last, first...
  2369.  
  2370. -----------------------------------------------------------------------------------------
  2371.  
  2372. user1@lab:~$ nano ./myscript
  2373.  
  2374. GNU nano 2.5.3 File: ./myscript Modified
  2375.  
  2376. #!/bin/bash
  2377.  
  2378. read -p "Enter your name: "
  2379. echo Hello $REPLY, welcome to my program.
  2380.  
  2381. user1@lab:~$ ./myscript
  2382. Enter your name: Adam
  2383. Hello Adam, welcome to my program.
  2384.  
  2385. -----------------------------------------------------------------------------------------
  2386.  
  2387. user1@lab:~$ nano ./myscript
  2388.  
  2389. GNU nano 2.5.3 File: ./myscript Modified
  2390.  
  2391. #!/bin/bash
  2392.  
  2393. if read -t 5 -p "Enter your name: " name
  2394. then
  2395. echo "Hello $name, welcome to my script"
  2396. else
  2397. echo "Sorry, too slow!"
  2398. fi
  2399.  
  2400. user1@lab:~$ ./myscript
  2401. Enter your name: Sorry, too slow!
  2402.  
  2403. user1@lab:~$ ./myscript
  2404. Enter your name: Adam
  2405. Hello Adam, welcome to my script
  2406.  
  2407. -----------------------------------------------------------------------------------------
  2408.  
  2409. user1@lab:~$ nano ./myscript
  2410.  
  2411. GNU nano 2.5.3 File: ./myscript Modified
  2412.  
  2413. #!/bin/bash
  2414.  
  2415. read -s -p "Enter your password: " pass
  2416. echo "Is your password really $pass?"
  2417.  
  2418. user1@lab:~$ ./myscript
  2419. Enter your password: Is your password really 1111?
  2420.  
  2421. user1@lab:~$ ./myscript
  2422. Enter your password: Is your password really test@123?
  2423.  
  2424. -----------------------------------------------------------------------------------------
  2425.  
  2426. user1@lab:~$ nano ./myscript
  2427.  
  2428. GNU nano 2.5.3 File: ./myscript Modified
  2429.  
  2430. #!/bin/bash
  2431.  
  2432. count=1
  2433.  
  2434. cat myfile | while read line
  2435. do
  2436. echo "Line $count: $line"
  2437. count=$(( $count + 1 ))
  2438. done
  2439. echo "Finished"
  2440.  
  2441. user1@lab:~$ ./myscript
  2442. Line 1: User1
  2443. Line 2: user1
  2444. Line 3: Web
  2445. Line 4: IT
  2446. Line 5: programing
  2447. Line 6: 2017
  2448. Line 7: ..
  2449. Finished
  2450.  
  2451. -----------------------------------------------------------------------------------------
  2452.  
  2453. user1@lab:~$ pwd >> myfile1
  2454. user1@lab:~$ cat ./myfile1
  2455. /home/user1
  2456.  
  2457. user1@lab:~$ ls -l xfile > myfile1
  2458. ls: cannot access 'xfile': No such file or directory
  2459.  
  2460. user1@lab:~$ ls -l xfile 2> myfile1
  2461. user1@lab:~$ cat ./myfile1
  2462. ls: cannot access 'xfile': No such file or directory
  2463.  
  2464. user1@lab:~$ ls -l myfile1 xfile anotherfile 2> errorcontent 1> correctcontent
  2465. user1@lab:~$ cat ./correctcontent
  2466. -rw-rw-r-- 1 user1 user1 53 Nov 5 22:19 myfile1
  2467. user1@lab:~$ cat ./errorcontent
  2468. ls: cannot access 'xfile': No such file or directory
  2469. ls: cannot access 'anotherfile': No such file or directory
  2470.  
  2471. user1@lab:~$ ls -l myfile1 xfile anotherfile &> content
  2472. user1@lab:~$ cat ./content
  2473. ls: cannot access 'xfile': No such file or directory
  2474. ls: cannot access 'anotherfile': No such file or directory
  2475. -rw-rw-r-- 1 user1 user1 53 Nov 5 22:19 myfile1
  2476.  
  2477. -----------------------------------------------------------------------------------------
  2478.  
  2479. user1@lab:~$ nano ./myscript
  2480.  
  2481. GNU nano 2.5.3 File: ./myscript Modified
  2482.  
  2483. #!/bin/bash
  2484.  
  2485. echo "This is an error" >&2
  2486. echo "This is normal output"
  2487.  
  2488. user1@lab:~$ ./myscript
  2489. This is an error
  2490. This is normal output
  2491.  
  2492. user1@lab:~$ ./myscript 2> content
  2493. This is normal output
  2494. user1@lab:~$ cat ./content
  2495. This is an error
  2496.  
  2497. -----------------------------------------------------------------------------------------
  2498.  
  2499. user1@lab:~$ nano ./myscript
  2500.  
  2501. GNU nano 2.5.3 File: ./myscript Modified
  2502.  
  2503. #!/bin/bash
  2504.  
  2505. exec 1> outfile
  2506. echo "This is a test of redirecting all output"
  2507. echo "from a shell script to another file."
  2508. echo "without having to redirect every line"
  2509.  
  2510. user1@lab:~$ ./myscript
  2511. user1@lab:~$ cat ./outfile
  2512. This is a test of redirecting all output
  2513. from a shell script to another file.
  2514. without having to redirect every line
  2515.  
  2516. -----------------------------------------------------------------------------------------
  2517.  
  2518. user1@lab:~$ nano ./myscript
  2519.  
  2520. GNU nano 2.5.3 File: ./myscript Modified
  2521.  
  2522. #!/bin/bash
  2523.  
  2524. exec 2> myerror
  2525. echo "This is the start of the script"
  2526. echo "now redirecting all output to another location"
  2527. exec 1> myfile
  2528. echo "This should go to the myfile file"
  2529. echo "and this should go to the myerror file" >&2
  2530.  
  2531. user1@lab:~$ ./myscript
  2532. This is the start of the script
  2533. now redirecting all output to another location
  2534.  
  2535. user1@lab:~$ cat ./myerror
  2536. and this should go to the myerror file
  2537.  
  2538. user1@lab:~$ cat ./myfile
  2539. This should go to the myfile file
  2540.  
  2541. -----------------------------------------------------------------------------------------
  2542.  
  2543. user1@lab:~$ nano ./myscript
  2544.  
  2545. GNU nano 2.5.3 File: ./myscript Modified
  2546.  
  2547. #!/bin/bash
  2548.  
  2549. exec 0< myfile
  2550.  
  2551. count=1
  2552.  
  2553. while read line
  2554. do
  2555. echo "Line #$count: $line"
  2556. count=$(( $count + 1 ))
  2557. done
  2558.  
  2559. user1@lab:~$ ./myscript
  2560. ./myscript: line 3: testfile: No such file or directory
  2561. user1@lab:~$ touch testfile
  2562. user1@lab:~$ echo -e 'this is the first line\nthis is the second line\nthis is t he third line' > testfile
  2563. user1@lab:~$ ./myscript
  2564. Line #1: this is the first line
  2565. Line #2: this is the second line
  2566. Line #3: this is the third line
  2567.  
  2568. -----------------------------------------------------------------------------------------
  2569.  
  2570. user1@lab:~$ nano ./myscript
  2571.  
  2572. GNU nano 2.5.3 File: ./myscript Modified
  2573.  
  2574. #!/bin/bash
  2575.  
  2576. exec 3> myfile
  2577. echo "This should display on the screen"
  2578. echo "and this should be stored in the file" >&3
  2579. echo "And this should be back on the screen"
  2580.  
  2581. user1@lab:~$ ./myscript
  2582. This should display on the screen
  2583. And this should be back on the screen
  2584. user1@lab:~$ cat ./myfile
  2585. and this should be stored in the file
  2586.  
  2587. -----------------------------------------------------------------------------------------
  2588.  
  2589. user1@lab:~$ nano ./myscript
  2590.  
  2591. GNU nano 2.5.3 File: ./myscript Modified
  2592.  
  2593. #!/bin/bash
  2594.  
  2595. exec 6<&0
  2596. exec 0< myfile
  2597.  
  2598. count=1
  2599.  
  2600. while read line
  2601. do
  2602. echo "Line #$count: $line"
  2603. count=$(( $count + 1 ))
  2604. done
  2605.  
  2606. exec 0<&6
  2607. read -p "Are you done now? " answer
  2608. case $answer in
  2609. y) echo "Goodbye";;
  2610. n) echo "Sorry, this is the end.";;
  2611. esac
  2612.  
  2613. user1@lab:~$ ./myscript
  2614. Line #1: First line
  2615. Line #2: Second line
  2616. Line #3: Third line
  2617. Are you done now? y
  2618. Goodbye
  2619.  
  2620. user1@lab:~$ ./myscript
  2621. Line #1: First line
  2622. Line #2: Second line
  2623. Line #3: Third line
  2624. Are you done now? n
  2625. Sorry, this is the end.
  2626.  
  2627. -----------------------------------------------------------------------------------------
  2628.  
  2629. user1@lab:~$ nano ./myscript
  2630.  
  2631. GNU nano 2.5.3 File: ./myscript Modified
  2632.  
  2633. #!/bin/bash
  2634.  
  2635. exec 3> myfile
  2636. echo "This is a test line of data" >&3
  2637. exec 3>&-
  2638. echo "This won't work" >&3
  2639.  
  2640. user1@lab:~$ ./myscript
  2641. ./myscript: line 6: 3: Bad file descriptor
  2642.  
  2643. -----------------------------------------------------------------------------------------
  2644.  
  2645. user1@lab:~$ lsof -a -p $$ -d 0,1,2
  2646. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  2647. bash 21637 user1 0u CHR 136,2 0t0 5 /dev/pts/2
  2648. bash 21637 user1 1u CHR 136,2 0t0 5 /dev/pts/2
  2649. bash 21637 user1 2u CHR 136,2 0t0 5 /dev/pts/2
  2650.  
  2651. -----------------------------------------------------------------------------------------
  2652.  
  2653. user1@lab:~$ nano ./myscript
  2654.  
  2655. GNU nano 2.5.3 File: ./myscript Modified
  2656.  
  2657. #!/bin/bash
  2658.  
  2659. exec 3> myfile1
  2660. exec 6> myfile2
  2661. exec 7< myfile3
  2662. lsof -a -p $$ -d 0,1,2,3,6,7
  2663.  
  2664. user1@lab:~$ ./myscript
  2665. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  2666. myscript 21895 user1 0u CHR 136,2 0t0 5 /dev/pts/2
  2667. myscript 21895 user1 1u CHR 136,2 0t0 5 /dev/pts/2
  2668. myscript 21895 user1 2u CHR 136,2 0t0 5 /dev/pts/2
  2669. myscript 21895 user1 3w REG 7,0 0 524496 /home/user1/myfile1
  2670. myscript 21895 user1 6w REG 7,0 0 524507 /home/user1/myfile2
  2671. myscript 21895 user1 7r REG 7,0 0 524508 /home/user1/myfile3
  2672.  
  2673. -----------------------------------------------------------------------------------------
  2674.  
  2675. user1@lab:~$ ls -al badfile anotherfile 2> /dev/null
  2676. user1@lab:~$ cat /dev/null > myfile
Add Comment
Please, Sign In to add comment