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:
- Your_Name="Mozhiyan"
- echo $your _name
- 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:
- For skill in Ada coffe Action Java
- Do
- echo "I am Good at ${skill}script"
- 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