Linux command: Script programming knowledge point ${#VARNAME} ${varname#*}. FILENAME reads the contents of the document

Source: Internet
Author: User


Script Programming Knowledge Points:

* FILE=/USR/LOCAL/SRC

test=${file#*/}: $TEST result is usr/local/src, with/as keyword, delete all strings from the left number first/and key/left.

dest=${file##*/}: $DEST result is src, with/keyword, delete the last keyword/and all the strings on the left. from left to right, the * number needs to be on the left side of the keyword


dotest=${file%/*}: $DOTEST result is/usr/local, with/as keyword, delete all strings from the right of the first/and the keyword/right.

dodest=${file%%/*}: $DODEST result is empty, with/as keyword, delete all strings from the last/and the right of the right number. from right to left, the * number needs to be on the right side of the keyword



1. How to get the length of a character in a variable:

${#VARNAME} VARNAME variable name

Usage:

[[email protected] ~]# varname1= ' testing SERVER '

[[email protected] ~]# echo "${#VARNAME1}"

14 statistic variable VARNAME1 the character length, the space also occupies the character length

2, how to get the screen display size of the number of lines and the total length of characters per line

Stty-f/dev/console Size

[Email protected] ~]# stty-f/dev/console size

25 80 25 Indicates the number of rows, 80 indicates the total length of each line of characters

[[email protected] ~]# a= ' stty-f/dev/console size '

[[email protected] ~]# echo ${a#*} Delete the first space and its left character as a space keyword

80


. /etc/sysconfig/network-scripts/ifcfg-eth0 Import the contents of the Ifcfg-eth0 file into the current document


Usage:

[Email protected] init.d]# vim/mnt/sysroot/etc/rc.d/init.d/network

#!/bin/bash
#
# chkconfig:35 09 90
# Description:network Service
Prog=network
. /etc/rc.d/init.d/functionsAdd the contents of the/etc/rc.d/init/d/functions text to the document.
Conf=/etc/sysconfig/network-scripts/ifcfg-eth0
. $CONF
Netmask=22

Start () {
Ifconfig eth0 $IPADDR/$NETMASK up
[-Z $GATEWAY] && route add default GW $GATEWAY
return 0
}
Stop () {
Ifconfig eth0 Down
}
Status () {
Ifconfig eth0
}
Usage () {
echo "$prog: {start|stop|restart|status|"
}
Case $ in
Start

Start
Success "Config network eth0.";
Stop
Stop
Success "Stop network card eth0.";
Restart
Stop
Start
Success "Restart network card eth0";;
Status
status;;
*)
Usage
Exit 1;;
Esac

This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1882485

Linux command: Script programming knowledge point ${#VARNAME} ${varname#*}. FILENAME reads the contents of the document

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.