Linux-shell assignment case/shell loop operation case

 

1. The shell command returns and assigns a value to a variable

(1) Two commonly used methods

A=`ls -la` backquote, run the command inside, and return the result to the variable A

A=$(ls -la) is equivalent to backticks

 

(2) Example

for element in $(ls -rlt GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA-20200611*)

do

echo $element

done

 

#Remove 1000 files in the folder

for file in $(ls |head -1000)

do

mv $file /home/ubuntu/seo/csv/v1/

done

 

2. Loop through the array

my_array=(

GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA-20200612-20200612.21203425722018425.juvo_us.txt

GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA-20200612-20200612.21210780886018425.juvo_us.txt

GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA-20200612-20200612.21199743596018425.juvo_us.txt

GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA-20200612-20200612.21207515550018425.juvo_us.txt

)

 

for element in ${my_array[@]}

do

echo $element

grep B07YD1F2R8 $element

done

 

 

Guess you like

Origin blog.csdn.net/helunqu2017/article/details/113823085