If in the shell script. Then.. Elif.. Then.if statement

Source: Internet
Author: User

First type:

#!/bin/bash service vsftpd start &>/dev/null if

[$-eq 0]

Then

echo "FTP is start"

Else

Service VSFTPD Start

Fi

The second type:

#!/bin/bash read-p "Input your file name" file_name

If [D-$file _name]//To determine whether the directory

Then

echo "This file is directory!"

Elif [-F $file _name]//is a file

Then

echo "This file is file"

elif [-C $file _name-o-b $file _name]//is a character device or block device, which is OK

Then

Echo ' This is block file ' else echo ' This file unknown '

Fi

[Root@redhat shellscripts]# LL/DEV/SDA BRW-RW----. 1 root Disk 8, 0 June 1 10:05/DEV/SDA

[Root@redhat shellscripts]# Ll/dev/tty crw-rw-rw-. 1 root TTY 5, 0 June 1 10:05/dev/tty

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

The third type:

#!/bin/bash

If [$#-ne 2]

Then

echo "Not Enough parameters"

Exit 0///If not 2, jump out of the loop

Fi

If [$1-eq $]

Then

echo "$ = $"

elif [$1-lt $]

Then

echo "$ < $"

Fi

Results of execution:

[Root@redhat shellscripts]# sh test.sh 1 1 1 = 1

[Root@redhat shellscripts]# sh test.sh 1 2 1 < 2 ~

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.