Home > OS >  A shell script problem
A shell script problem

Time:11-11

Ask a question:
Background: the name of a folder there are a number of similar documents, such as pi_1_0 pi_2_0 pi_3_1... ,
Objective: shell script implementation will find all the documents folder, in another folder to create a name is processed by the corresponding documents, such as find pi_1_1, corresponding is also processed pi_1_1;
Problem: when I was inside the folder to find the document file name contains variables, shell script can't identify,
For ((I=0; i<255; I++))
Do
For ((j=0; J<255; J++))
Do
If [-e bin/pi_ $i_ $j_]; Then # variables included here, I met problems in
# # #
Fi
The done
The done
I tried this:
For ((I=0; i<255; I++))
Do
For ((j=0; J<255; J++))
Do
B="pi_ $i_ $j # will make variable expansion in double quotation marks
If [-e bin/$b_]; Then
# # #
Fi
The done
The done
But still won't do, how should deal with to my purpose?

CodePudding user response:

If [-e bin/pi_ $i_ $j_]; Then this place into a
If [-e bin/pi_ ${I} ${j} _ _]; Then have a try

CodePudding user response:

And $I $j value is not the same, does not need to be nested, cut a nested

CodePudding user response:

reference 1st floor brand response:
if [-e bin/pi_ $i_ $j_]; Then this place into a
If [-e bin/pi_ ${I} ${j} _ _]; Then try

Indeed so, variable expansion, bash saw $var will all behind the $character, until the first separator as a variable name,
Underline not separator, so $i_ $j is equivalent to ${i_} ${j}, as there is no definition, i_ so empty, only j,
In order to avoid this situation, the general advice is wrapped in use {} variable names,
  • Related