I want to write a very simple script , which takes a process name , and return the tail of the last file name which contains the process name.
I wrote something like that :
#!/bin/sh
tail $(ls -t *"$1"*| head -1) -f
My question:
-
Do I need the first line?
-
Why isn’t
ls -t *"$1"*| head -1 | tail -fworking? -
Is there a better way to do it?
1: The first line is a so called she-bang, read the description here:
2:
tailcan’t take the filename from the stdin: It can either take the text on the stdin or a file as parameter. See the man page for this.3: No better solution comes to my mind: Pay attention to filenames containing spaces: This does not work with your current solution, you need to add quotes around the
$()block.