You can use set -x
in you script, and combine it with redirecting the error stream 2>
to a file.
So at the beginning of your script, use either:
#!/bin/bash -x
Or
#!/bin/bash
set -x
Then, run your script like this:
./file.sh 2> found_commands.txt
For your script, the resulting file would be:
+ echo "######################"
+ echo "# FF_groesse_position"
+ echo "######################"
+ echo
+ echo
+ sleep=5
+ echo "Programm area"
+ firefox
+ sleep 5
+ echo
+ echo
++ xdotool getdisplaygeometry
++ cut -d ' ' -f1
+ x=$(xdotool getdisplaygeometry | cut -d ' ' -f1 )
++ xdotool getdisplaygeometry
++ cut -d ' ' -f1
+ y=$(xdotool getdisplaygeometry | cut -d ' ' -f2 )
+ echo "x=$x"
+ echo "y=$y"
+ echo
+ echo
++ wmctrl -lG
++ grep Desktop
++ tr -s ' '
++ cut -d ' ' -f5
+ x=$(wmctrl -lG | grep Desktop | tr -s ' ' | cut -d ' ' -f5 )
++ wmctrl -lG
++ grep Desktop
++ tr -s ' '
++ cut -d ' ' -f5
+ y=$(wmctrl -lG | grep Desktop | tr -s ' ' | cut -d ' ' -f6 )
+ echo "x=$x"
+ echo "y=$y"
+ echo
+ echo
+ read -p "Press Enter or Ctl + C"
You can then process your output file, and remove all variable definitions with the following Regular Expression*
egrep -v "^\++\ ([a-zA-Z])\w*\=" found_commands.txt
resulting in:
+ echo "######################"
+ echo "# FF_groesse_position"
+ echo "######################"
+ echo
+ echo
+ echo "Programm area"
+ firefox
+ sleep 5
+ echo
+ echo
++ xdotool getdisplaygeometry
++ cut -d ' ' -f1
++ xdotool getdisplaygeometry
++ cut -d ' ' -f1
+ echo "x=$x"
+ echo "y=$y"
+ echo
+ echo
++ wmctrl -lG
++ grep Desktop
++ tr -s ' '
++ cut -d ' ' -f5
++ wmctrl -lG
++ grep Desktop
++ tr -s ' '
++ cut -d ' ' -f5
+ echo "x=$x"
+ echo "y=$y"
+ echo
+ echo
+ read -p "Press Enter or Ctl + C"
Finally, you can extract only the second word of each line with
egrep -v "^\++\ ([a-zA-Z])\w*\=" found_commands.txt | cut -d ' ' -f2 }'
resulting in:
echo
echo
echo
echo
echo
echo
firefox
sleep
echo
echo
xdotool
cut
xdotool
cut
echo
echo
echo
echo
wmctrl
grep
tr
cut
wmctrl
grep
tr
cut
echo
echo
echo
echo
read
You can combine it into a single command using Bash subshells and redirection, like this:
./file.sh 2> >(egrep -v "^\++\ ([a-zA-Z])\w*\=" | cut -d ' ' -f2 > found_commands.txt)
Now the file found_commands.txt
will have the processed output.
If you don't want duplicates, and only want to know which commands are run, filter through sort-u
(unique option) with
./file.sh 2> >(egrep -v "^\++\ ([a-zA-Z])\w*\=" | cut -d ' ' -f2 | sort -u > found_commands.txt)
resulting in an alphabetic list of "dependencies" for the script:
cut
echo
firefox
grep
read
sleep
tr
wmctrl
xdotool
*RegEx breakdown
^
beginning of line
\+
plus sign
+
1 or more of the preceding element
\
space
(
begin group
[a-z][A-Z]
any English letter
)
end group
\w
word character (a-z
, A-Z
, 0-9
and _
)
*
0 or more of the preceeding element
\=
equal sign