I'm still quite new to bash scripting and I need a very simple script that, if there is command history, displays it, and, if there isn't, informs the user that there is no command history.
What I have so far is this:
#!/bin/bash
if [ -n "$(history)" ]
then
history
else
echo "No entered commands."
fi
But, no matter whether the history has or hasn't been cleared with history -c
, the above script returns:
/path/to/script.sh: 3: history: not found
No entered commands.
What exactly is going wrong and how can I adapt or rewrite this script to work?
)
and the-gt
, i.e. the line should readif [ "$(history | wc -l)" -gt 0 ]
? Regardless, I'm gettinghistory: not found
on lines 3 and 5 using your suggestion and my amendment.