Storing Multi line commands in history using shopt

Storing Multi line commands in history using shopt


It is hard to reuse multi-line commands as the newlines are replaced by semicolon and the many line command is converted to a single line. For example:

for i in $( ls *.txt)
do
pwd
echo $i
cp $i /bin
done

After executing it, when you press up button to reuse it, the command becomes:

for i in $( ls *.txt); do pwd; echo $i; cp $i /bin; done

Forget about reusing, I cant even understand what it does when so many things are stuffed in one line!
I found a way using which it is possible to retain the newlines in history using shopt.

shopt -s lithist

Now when you press up button you will see the command in multiple lines! win!

If you want this to be enabled by default add "shopt -s lithist" at the end of file ~/.bashrc


UPDATE
Also multi-line commands are screwed up when you add comments. For example

for i in $(ls)
do
echo "a"
#echo $i
done

becomes for i in $(ls); do echo "a" done (note that there is no semicolon after echo "a". Hence it takes echo "a" done as one command). Hence you will end up scratching your head to figure out what went wrong :P





download file now

Comments

Popular posts from this blog

Spider Man Friend Or Foe ISO Free Download PPSSPP Setting

Sorry Mutter closed unexpectedly on Ubuntu 10 10

Solution Ubuntu 10 04 minimize maximize and close button to right