LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   BASH: More on the "silly" script idea. (https://www.linuxquestions.org/questions/linux-newbie-8/bash-more-on-the-silly-script-idea-869900/)

SilversleevesX 03-21-2011 12:23 AM

BASH: More on the "silly" script idea.
 
Background: http://www.linuxquestions.org/questi...t-idea-869866/

Well, it won't switch -- keeps telling me histexpand is off. I suppose it's because it is in the subshell invoked with my slashbang (sic) line. So how would one go about getting the "real" state of histexpand, for the shell that starts when my dotfiles are sourced?

I pared down one part of the script to read:
Code:

c=$(set -o | grep histexpand)
echo $c
if [[ "$c" =~ *on* ]]; then
        echo -e "History expansion is currently ON."

fi

and ran it. set -o with grep echo'ed
Code:

histexpand off
which of course failed to satisfy the 'if' condition. This is how I knew the state of things was different in the script's shell from my session shell.

Meanwhile,
Code:

set -o | grep histexpand
from the terminal session gave me an on.

So how would one get the parent shell state, if that's the right term for it?

Looking forward to a reply.

BZT

grail 03-21-2011 02:01 AM

Well, doing a quick 'help set' revealed that you can do the following:
Code:

set -H
c=$(set -o | grep histexpand)
echo $c

Output:
Code:

histexpand    on
Also, in your 'if', as you are using a type of regular expression the astericks serve no purpose:
Code:

if [[ "$c" =~ *on* ]]; then

# same as
if [[ "$c" =~ on ]]; then



All times are GMT -5. The time now is 04:17 AM.