A small script written by the shell

Source: Internet
Author: User

You want to use a shell script to convert all the images in a folder to a pixel.

Here are some of the wrong places:

1. When defining a variable, the variable name does not add a dollar sign ($), such as:

  VariableName="value"

Note that there can be no spaces between the variable name and the equals sign, which may be different from any programming language you are familiar with. At the same time, the name of the variable names must follow the following rules:

    • The first character must be a letter (a-z,a-z).
    • You can use an underscore (_) without spaces in the middle.
    • Punctuation cannot be used.
    • You can't use the keywords in bash (you can see the reserved keywords using the help command).

2. Using a defined variable, simply precede the variable name with a dollar sign ($), such as:

    1. Your_Name="Mozhiyan"
    2. echo $your _name
    3. echo ${your_name}

The curly braces outside the variable name are optional, plus the curly braces are used to help the interpreter identify the bounds of the variable, such as the following:

    1. For skill in Ada coffe Action Java
    2. Do
    3. echo "I am Good at ${skill}script"
    4. Done

If you do not add curly braces to the skill variable and write the echo "I am good at $skillScript", the interpreter will treat $skillscript as a variable (whose value is null) and the result of the code execution is not what we expect it to look like. It is a good programming habit to add curly braces to all variables.

3. Variable operation:

S=0 #定义一个求和变量, the initial value is 0.

t= ' expr$1**$2 ' #用expr改变运算顺序, seeking X's Y-square.

T=$[T*3] #t乘以3.

S=$[s+t] #结果相加.

T=$[$1**2] #求x的平方.

T=$[T*4] #结果乘以4.

S=$[s+t] #结果相加.

t= ' expr$2*5 ' #求5y的值.

S=$[s+t] #结果相加.

S=$[S+6] #结果加上6.

Echo$s #输出结果.

echo$ ((a%b)) #取余

Correct code:

 #!/bin/bash#  mkdir  Detection-crowdai_newcount  =0  for  image in  $ ( ls  detection-crowdai)  do   count  =$[count+1   " echo  "  Span style= "COLOR: #800000" >hello world!   "
Echo $image #convert -resize 800x500 image image Done echo $count

$ (LS Detection-crowdai) is equivalent to a variable that implements access to all files in a folder. Echo $image can display all filenames under a folder

Detection-crowdai is in the ~, because this shell script is in the ~ directory, so do not add absolute path:/home/bnrc/detection-crowdai, also do not write/detection-crowdai, This will be an error saying that the file could not be found.

A small script written by the shell

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.