shell--to Be Continued

Source: Internet
Author: User

Bash variables

? variable = value

? Reference by: $ variable

[Email protected] desktop]# hi="Hello,and Welcome to $ (hostname). "  Echo  $HIHello, and welcome to localhost.localdomain.[ [Email protected] desktop]#

? &>: Redirect all outputs

? 2>&1: redirect stderr to stdout

? >: Redirected stdout

? 2>: Redirect StdErr

 [[email protected] test]# ll *. sh  *.txt > AAA  ls : Cannot access *.txt:no such file   or directory[[email protected] test]#  cat  Span style= "COLOR: #000000" > AAA -rwxr--r--. 1  root root 158  June 28  06 : 36  test1. sh -rwxrwxrwx. 1  root root 59  June 28  06 : 33  test. sh    
[email protected] test]# ll*.SH*.txt2>BBB-rwxr--r--.1Root root158June -  .: $Test1.SH-rwxrwxrwx.1Root root -June -  .: -Test.SH[email protected] test]#CatBBBls: Cannot access *.txt:no suchfileor directory
 [[email protected "test]# ll  *. sh  *.txt &> ccc[[email protected] test]#  cat   CCC  ls : Cannot access *.txt:no such file   or directory -rwxr--r--. 1  root root 158  June 28  06 : 36  test1. sh -rwxrwxrwx. 1  root root 59  June 28  06 : 33  test. sh  

redirect from file to standard input:

Cat1158: test1. SH 1 root root  : Test.  SH
 [[email protected] test]#  cat  AAA | tr   " a-z   "  " a-z   "-rwxr--r--. 1  root root 158  June 28  06 : 36   TEST1. SH -rwxrwxrwx. 1  root root 59  June 28  06 : 33   TEST. SH  
TR ' A- z ' ' A- z '  <AAA1158:  TEST1. SH1 root root  : TEST. Sh

For statement:

[Email protected] test]#Cat  for.SH #!/bin/Bash forNAMEinchJoe Jak Sky DoMESSAGE='Hello World'   EchoThe He name is $NAME."$NAME say $MESSAGE!" Done[email protected] test]#./ for.SHHe name is Joe. Joe Say hello world!The He name is Jak. Jak Say hello world!He name is sky. Sky Say hello world![email protected] test]#

[email protected] test]# cat for1.sh
#!/bin/bash
For num in $ (SEQ 1 6)
Do
Echo $num
Done
[Email protected] test]#./for1.sh
1
2
3
4
5
6
[Email protected] test]#

[Email protected] test]#Cat if.SH #!/bin/Bashif Ping-c1-w2128.0.0.1&>/dev/NULL; Then    EchoNetwork SERVICE is up!elif grepNetwork/weihu.txt &>/dev/NULL; Then    EchoNetwork Service isinchMaintenance!Else   EchoStation was down!fi[email protected] test]#

shell--to Be Continued

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.