Thanks Caine. I'll need to set a variable then, to be used in the next part of the script. (First time playing with this kind of thing). This is working for me so far:
Code:
mount | grep /dev/mmcblk0 | awk -v avar=$dir '{print $3}'
mkdir $dir screenshots
The above is just the install script. The screengrab script itself will need to grep again for the save path (haven't tested this one yet):
Code:
mount | grep /dev/mmcblk0 | awk -v avar=$dir '{print $3}'
fbgrab $dir/screenshots/filename.png
A couple of thoughts..
- The 'print' function seems superfluous to me, I just want to set a variable. But I get polite suggestion on usage if I don't include it. Insight on this?
- Perhaps I could do away with folder creation in the install script all together, and just have the screengrab script check the location, and create the folder if needed before saving the shot. That feels a little inefficient to me, but it would mean it doesn't matter which SD card you have in.
The print in the awk script just tells the script to dump $3 (i.e. the third column) to the standard output (i.e. print it to the terminal).
If you only reference the result of the awk script once, then you do not need to create a variable for it:
Code:
mkdir $(mount | awk '/^\/dev\/mmcblk0p/ {print $3}')/screenshots
In this particular case, I eliminated grep as awk can actually do the matching itself. The term '/^\/dev\/mmcblk0p/ is a regular expression which looks for /dev/mmcblk0p at the beginning of a line (the / needs to be escaped).
The form of the Awk script here is: '/search_pattern/ {action}', which means that action is executed if a line matches the regular expression
search_pattern
If you need that value multiple times in the same shell script then simply assign the result to a variable like this:
Code:
dir=$(mount | awk '/^\/dev\/mmcblk0p/ {print $3}')
mkdir $dir/screenshots
name=screen$(date +%y%m%d-%H%M%S).png
fbgrab $dir/screenshots/$name
notify-send 'captured screen as' $name
The optional notify-send will show a small popup dialog in the bottom right corner of your screen.