LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-21-2011, 12:23 AM   #1
SilversleevesX
Member
 
Registered: May 2009
Posts: 181
Blog Entries: 9

Rep: Reputation: 15
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
 
Old 03-21-2011, 02:01 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
[SOLVED] troubles with bash script tests "-z" and "-n" SaintDanBert Linux - Software 7 04-10-2012 09:26 AM
[SOLVED] BASH: Error on "silly" script idea. SilversleevesX Linux - Newbie 2 03-20-2011 11:44 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration