I created a shell script file named 1.sh with only one echo command:


I made the file 1.sh executable and tried to run the file in the terminal by running the command


It printed an empty line on the terminal. But when I run this command at the shell prompt I get 1000 as output.

Why is the echo not working in my shell script?

1 Answer 1


You script is running in a non-interactive shell, which has history disabled by default (assuming it supports history, but that’s the case in most sh implementations nowadays); thus HISTSIZE is empty.

If you forcibly enable history (in Bash at least), you’ll get the default value:

set -o history
  • But i have a query. When i just echo $HISTSIZE in commandline ,i get a value 1000. But when i does it by enabling history in shell script, i get a value 500. Why there is a difference in two values? Dec 17, 2017 at 10:05
  • You get different values because, when the shell runs a script, it doesn’t process your startup scripts (.profile, .bashrc etc.). Thus HISTSIZE is set to the default value, 500, rather than the value your startup scripts set, 1000. Dec 17, 2017 at 10:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .