Guestfish: generating inline commands from shell scripts

Hairy feature of the week is the new ability in guestfish ≥ 1.9.5 to use shell script inline to generate guestfish commands. This simple example adapted from the manual demonstrates how to touch files /foo.1, /foo.2 through /foo.100:

><fs> <! for n in `seq 1 100`; do echo touch /foo.$n; done

How this works is it passes everything after the <! to the shell (actually to popen(3)), it then reads what this prints out:

touch /foo.1
touch /foo.2
etc.

and it executes them as guestfish commands.

You can use this to emulate variables in guestfish (although this is probably not very advisable).

><fs> inspect-get-roots | head -1 > /tmp/root
><fs> !cat /tmp/root
/dev/vg_f13x64/lv_root
><fs> <! echo inspect-get-product-name $(</tmp/root)
Fedora release 14 (Laughlin)

The “variable” here is stored in the file /tmp/root. This is all obviously rather hairy and at some point we may add proper variables to guestfish.

Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s