Rhys
Rhys

Reputation: 2877

How to input tail -1 into sh script var

AIM: I would like to tail the last line of the file.txt and input into a variable to use for substitution via sed.

CODE:

 ALARM_POPUP_CONTENT=(tail -1 /logs/file.txt)
 ALARM_POPUP_CONTENT=tail -1 /logs/file.txt

OUTCOME:

This is only outputtin the work 'tail' or an error command not found for the seond option. Any suggestions?

Upvotes: 2

Views: 11333

Answers (1)

jedwards
jedwards

Reputation: 30210

Try:

ALARM_POPUP_CONTENT=$(tail -1 /logs/file.txt)

or with backticks:

ALARM_POPUP_CONTENT=`tail -1 /logs/file.txt`

Upvotes: 3

Related Questions