0

I'm using bash to make a little program that is using irecovery, a tool for iOS devices and I'm trying to automate the process of using it.

I have created variables that search for files in a specific folder, so other users can use the same program with different files, though the problem is that the variables aren't replaced by the names of the files and so "irecovery" can't access them.

My code looks like this

#!/bin/bash

dtree=$(find Downgrade -type f -iname device*)
ramdisk=$(find Downgrade -type f -name *.dmg)
kernel=$(find Downgrade -type f -iname kernel*)

./irecovery -s <<EOF

/send $dtree
devicetree
/send $ramdisk
ramdisk
/send $kernel
bootx
reboot
EOF

Now how would I get bash to print out the variable before it is used by irecovery, or make irecovery use the variable defined in bash?

2 Answers2

0

You can use echo command before ./irecovery -s command to view what is passing through irecovery.
Like this:

echo dtree:$dtree
echo ramdisk:$ramdisk
echo kernel:$kernel 

You can pass variables,check like this:
cat << EOF
$dtree
EOF

Arash
  • 400
  • 4
  • 11
  • My files are located correctly, echo prints the right files. I tried out using the command with no substitution and it worked, though I had to replace the variables with the actual file names, since they can't be passed that way, or can they? – TheOnlyGermanGuy Apr 02 '16 at 18:28
  • Yes they can, I mentioned in the Answer – Arash Apr 02 '16 at 19:30
  • I used `echo $dtree` and that worked fine after I removed the "" from EOF, thanks for your answer though. – TheOnlyGermanGuy Apr 03 '16 at 18:07
-2

I found a solution by myself now. I removed the quotes from EOF, so there's substitution and after each

/send

I used an echo command to echo my files and that worked. So now for example it looks like:

./irecovery -s <<EOF

/send `echo $dtree`

EOF
  • 2
    That's a [useless use of `echo`](http://www.iki.fi/era/unix/award.html#echo) and yet another dangerous quoting error. – tripleee Apr 04 '16 at 09:16
  • @tripleee Is there a better way to print out the variable? – TheOnlyGermanGuy Apr 04 '16 at 12:03
  • 1
    `/send $dtree` should work just fine, unless you specifically *require* the shell to wreck any whitespace and expand any wildcards in the value of `$dtree` (in which case your question should clearly point out this requirement). See also http://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-variable – tripleee Apr 04 '16 at 12:05
  • @tripleee The problem is that $dtree is passed "as it is" and is not expanded. So I used echo. – TheOnlyGermanGuy Apr 04 '16 at 12:08
  • `echo` doesn't expand variables. The shell does. – Etan Reisner Apr 04 '16 at 13:21
  • @tripleee Yes but the main problem is that in the command irecovery which I use they don't get expanded like in cat – TheOnlyGermanGuy Apr 04 '16 at 13:23
  • Neither `cat` nor your command expand any variables. See @EtanReisner's comment just above yours. – tripleee Apr 04 '16 at 15:42