I have a script to identify flash files in memory to be copied or passed to a program such as vlc for playback.
#!/bin/bash
pid=($(ps aux | grep flash | grep -v grep | grep -v bin/flash))
cd "/proc/${pid[1]}/fd"
file=($(echo `ls -l | grep /tmp/`))
file="${file[8]}"
echo "$file"
This works well but I want it to return each matching file, as it is it only returns the first one.
I would normally do something like a multidimensional array but bash doesn’t have those and even if it did I wouldn’t know the syntax.
How do I split the output by line and then echo the [8] value from each?
You could use
awkfor this:This is not failsafe at all (parsing the output of
lsgenerally isn’t).A safer approach if your
findsupports it would be:(Still not safe if you have spaces in the filename.)
This should be pretty robust and give you a bash array to boot:
(still fails with filenames that contain
\n.)