linuxshell%
Linux command SHELL programming: if the number is greater than 0, output the number; How to write a program whose output value is 0 when it is less than or equal to 0?

#! /bin/bashecho "pleaseinputnumber:" # Keyboard reads the value assigned to the variable numreadnum# to judge whether the value of num is a number or not, otherwise it exits expr$num+0 directly.

1 & gt; /dev/null

2> 1 if then echo "$ {num} is notanumber!" Exit0fi# judges whether the value of variable num is greater than 0, and if it is, ho $ num else echoes 0fi.

How to intercept a string in Linux shell programming?

Briefly introduce the detailed methods of Shell string interception, such as intercepting the specified number of words, intercepting according to the specified string, and dividing according to the specified requirements.

1.Linuxshell intercepts the first 8 bits of a character variable as follows: 2. Intercept 1 according to the specified string. The first method: $ {variable # * string} truncates the string after the last string from left to right $ {variable # * string} truncates the string after the first string from left to right $ {variable%% string *} truncates the string after the last string from right to left. The string "*" after the first string is truncated from right to left is just a wildcard. There is no need to divide it according to the specified requirements: for example, get the suffix Linuxshell command, -d?

Part is a judgment expression, and -d means judging whether it is a directory. It is a logical AND operator (similar to C syntax). The following statement will be executed only if the previous judgment holds (returning logical truth). In a word, it means: if /root/Desktop/ is a directory, execute chmod777 /root/Desktop/download. If /root/desktop/ is not a directory (the directory does not exist), execute chmod777/root/ desktop/download. The desktop is actually dealing with the situation that the desktop is in English and Chinese.