Home > Software engineering >  solaris 10 tail variable lines
solaris 10 tail variable lines

Time:07-15

I previously used ksh for this script. I would create the variable like say LINE=8 and then use tail -$LINE <file> and everything was great. Now I am trying to rewrite this in bash, but still in Solaris 10 bash. No matter how I write this tail line in bash, it is not using the value of the variable:

tail -$LINE <file> = "tail: cannot open input"

tail -${LINE} <file> = "tail: cannot open input"

Anyone have an idea how to cite the variable correctly in Solaris 10 bash so this works correctly?

CodePudding user response:

You could try using cat and pipe it to tail:

cat <filename> | tail -${LINE}

CodePudding user response:

You might get this if the LINE variable contains non-digits: on my Mac

$ LINE=8
$ tail -$LINE .bashrc
[expected contents]

But if add a carriage return to the variable

$ LINE=$'8\r'
$ tail -$LINE .bashrc
tail: option used in invalid context -- 8

Check your script file for \r\n line endings.

  • Related