find /var/mobile/ maxdepth -2 name "$x" >> /"$x".txt
The thing is I want to repeat this script and pull out a variable from a text file like this (each line = new variable $x and another run of the whole command)
So... like this:printf "cp /path/to/app.app/folder/$x.plist" >> /var/mobile/z_folder/"$x".sh
this:printf "cp /path/to/app.app/folder/"$x".plist" >> /var/mobile/z_folder/"$x".sh
or this?:
printf "cp /path/to/app.app/folder/""$x"".plist" >> /var/mobile/z_folder/"$x".sh
??
I think the first two didn't work for me... do they for you ?
The first two ways don't work, because the first $x is expanded. The third also does not work, and is quite confusing. To make it clear and easy to understand, the two best ways to write this are:
1) generating code
2) using eval for basic, simple things
3) building shell scripts with shell scripts
...chances are you've missed or skipped the obvious way.
Creating 10,000 nearly-identical scripts with slightly different variables? Why not have it take a parameter, then call the same one 10,000 times? In fact, if it's a script with one line, why call a script at all?
Generating code and storing it for later? Why not generate it later and avoid the storing, or just store a list of files instead of an entire script?
In fact, why not just copy then and there, now or later, without generating code? The shell's fully capable of doing all these things.
All of the suggestions posted above share one and the same problem (at least when I use them with my shell environment):
One of the two variables doesn't get extracted.
Results:
1st doesn't get extracted: swallowed line or part that contains variable
2nd doesn't get extracted: all paths are written into a $x.sh file that magically contains all paths with the variables extracted.
I'd gladly listen to further ideas regarding this.
Till then:
I went another route to achieve what I want:
while read x
do
printf "cp /path/to/app/xtzdero204.plist " >> /var/mobile/z_renapps/"$x".sh
sed -i "s|xtzdero204|$x|g" /var/mobile/z_renapps/"$x".sh
done < /Applications/RenApple.app/applist.txt
We still do not understand why you wish to make 10,000 individual scripts with slight differences. This kind of "need" usually points to a poor understanding of the shell.
Well, assuming there are more lines, the answer is that the 52nd line $x poisoned CODE and it hung. Put an echo "x='$x'" before CODE to make sure which line in toxic.