Re: Passing variables to and from custom programs

2010-02-07 Thread Mike Stroyan
On Sat, Feb 06, 2010 at 05:35:21PM -0800, DennisW wrote:
 On Feb 6, 5:37 pm, djackn jack.nadel...@yahoo.com wrote:
      Result = myIpExec(${IPaddr1} ${IPaddr2} ${IPaddr3} ${IPaddr4})
 
  myIpExec is a c program that normally uses scanf to prompt the user
  for the IP addresses and returns 0 or 1.
  I plan to use the script to test the program for various inputs.
 
 It is more likely that this would work:
 
 Result=$(echo {IPaddr1} ${IPaddr2} ${IPaddr3} ${IPaddr4} | myIpExec)
 
 Note that there are no spaces around the equal sign.

  If the result of 'myIpExec' is output to stdout then you could put that into
a shell variable with the syntax that DennisW showed you.  But you may have a
problem with parsing it because any prompt for the IP addresses will be included
at the front of that variable.

  If the result of 'myIpExec' is actually a return value from main() then you
would access that as the shell variable $? just after the program is run.

  The bash 'here string' notation could be used as an alternative to the
echo pipeline notation.  It is not as portable.  But I like the way it looks
in shell script.  It is used like this-

myIpExec  {IPaddr1} ${IPaddr2} ${IPaddr3} ${IPaddr4}
Result=$?

-- 
Mike Stroyan m...@stroyan.net




Re: filename pattern case-insensitive, but why?

2009-09-23 Thread Mike Stroyan
On Tue, Sep 22, 2009 at 02:36:30AM -0700, thahn01 wrote:
 
 Hello, If I try something like:
 
 $ touch a.c b.c A.c
 $ ls [a-z]*.c
 a.c  A.c  b.c
 
 then I get A.c in the output, even if no capital letters are to be found.

  The [a-z] range expression matches characters between a and z in the
current locale's collation order.  The collation order for en_US.UTF-8 and
other locales has uppercase and lowercase alphabetic characters together.
So in those locales your range includes 'a' through 'z' and 'A' through
'Y'.  You can change the locale to C or POSIX to get plain ascii
collation order.  You can see the collation order using the sort command.

for c in {32..126}; do eval printf '%c - %d\n' $(printf $'%o' $c) 
$c;done | sort -k 1.1,1.1

for c in {32..126}; do eval printf '%c - %d\n' $(printf $'%o' $c) 
$c;done | LANG=C sort -k 1.1,1.1

The collation order lists 'a' before 'A', but actually lets a later
character break a tie between otherwise equal uppercase and lowercase
characters.  Sort will arrange 'a1', 'A1', 'a2', and 'A2' with the '1'
vs. '2' characters acting as a tiebreaker.

-- 
Mike Stroyan m...@stroyan.net




Re: string format

2009-09-23 Thread Mike Stroyan
On Wed, Sep 23, 2009 at 12:03:56PM -0700, eatsubway wrote:
 
 hello, i have a simple question.  I have a string which i would like to
 format by replacing spaces with newlines and tabs, and also adding a tab to
 the beginning.

  The printf builtin will do that easily.  If you give it a format with one
argument then it will repeat that format for each of multiple arguments.

printf \t%s\n $MyVar

  If you really want to only break up your string at spaces then you will
want to momentarily change IFS to just   instead of the default that
matches spaces, tabs, and newlines.  Be sure to put IFS back to the
default for the benefit of later parts of your shell script that expect
the default.  You can do that with another assignment or with a subshell
like this-

( IFS= ; printf \t%s\n $MyVar )

-- 
Mike Stroyan m...@stroyan.net




Re: Inconsistent output in terminal emulator

2009-08-24 Thread Mike Stroyan
On Mon, Aug 24, 2009 at 09:44:36AM +0200, Ralf Goertz wrote:
 I hope you don't mind my jumping in with a question that is only
 remotely related. But since you guys seem to be experts on tty…
 
 I have an embedded device running a linux kernel that uses a serial port
 as console (console=ttyAS0,115200). I can log on to that device via
 telnet. Is it possible to see what is written to that console from
 within the telnet session using features provided by the shell?

  It is very likely that an embedded device is using busybox as the shell
rather than bash.  That would be good news for you as there is a setconsole
builtin for busybox that will redirect console output to a different device
such as the telnet pty.  Bash does not include console redirection.
Busybox may be built with or without the setconsole feature.  See the
http://man-wiki.net/index.php/1:busybox manual and check the details of
your device.

-- 
Mike Stroyan m...@stroyan.net




Re: Need info on input keys

2009-08-02 Thread Mike Stroyan
On Tue, Jul 07, 2009 at 12:17:37PM +0530, seshikanth varma wrote:
 I need to implement history feature in an emulated shell environment. I need
 to read keys present in the keyboard and define handler for each key. For
 example, Up arrow gives the previous command in the history. Can u please
 tell me how to make a start?

  Have a look at the readline library, which bash uses.
http://tiswww.case.edu/php/chet/readline/rltop.html

-- 
Mike Stroyan m...@stroyan.net




Re: Missing .bash_history Entries

2008-05-24 Thread Mike Stroyan
On Sat, May 24, 2008 at 10:46:40AM -0700, Dave Jarvis wrote:
 Description:
 It is possible to execute commands from the command-line
 without them appearing in the .bash_history file. This is a slight
 nuisance as any command that is accidentally preceded with a space
 will not appear when cycling through commands using the arrow keys.

  That is a documented feature.  It only ignores lines starting with
space if HISTCONTROL is set to a value including ignorespace or ignoreboth.

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: finding the index at which two strings differ

2008-05-06 Thread Mike Stroyan
On Tue, May 06, 2008 at 01:29:13PM -0600, Bob Proulx wrote:
 Poor Yorick wrote:
  Looking for a simple ways to output the index at which two strings
  differ.  Here is one:
  
  cmp (echo hello) (echo help) | cut -d' ' -f5 | tr -d ,
  
  Any other suggestions?

You could use substring expansion to compare characters one by one.

#!/bin/bash
a=$1
b=$2
if [[ $a == $b ]]
then
  echo '$a' and '$b' are the same
else
  i=0
  while [[ ${a:$i:1} == ${b:$i:1} ]]
  do
let i++
  done
  let i++
  echo '$a' and '$b' differ in character $i
fi

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: converting an array into a single variable

2008-02-20 Thread Mike Stroyan
On Wed, Feb 20, 2008 at 11:42:38AM -0800, Natan Shar wrote:
 
 Here's what I am trying to do:
 
 I have a directory full of files. They are all image files and are numbered
 using an id number, and underscore, and a detail number. Example:
 
 for item 123456, there may be from 0 to 25 images with names such as
 '123456_0.JPG' or '123456_47.JPG'
 
 I need to collect the names of these files and then convert it into one
 variable that I can then write into a database. My ideal example for the
 above would be'123456_0.JPG,123456_47.JPG'
a=(www/images/*);a=$(IFS=,; echo ${a[*]};);a=${a//www\/images\/};echo $a

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: Launching Apps to different desktops

2008-02-07 Thread Mike Stroyan
On Thu, Feb 07, 2008 at 02:39:31PM -0800, HandyAndy0 wrote:
 
 I need to write a bash script that launches several tasks. Two of the tasks
 are gui based. One needs to run in the current desktop, while the other in
 an alternate desktop of choice. Any clues? System: Red Hat Enterprise 4.

  This really isn't a bash topic.  It is specific to gnome and the particular
applications you are running.

  Gnome window managers will look for a _WIN_WORKSPACE property as described 
here-
http://developer.gnome.org/doc/standards/wm/c44.html#AEN46
But there seems to be no standard gtk or other toolkit option that will set that
property.  The eterm application has a '-D desktop' or '--desktop desktop'
option that will set that property.  If you are very lucky there may be
a similar option to the applications you are starting.

  Another approach is to use a wrapper application like kstart or
devilspie to set the property on the window after it starts to map.
That is likely to cause a visible flash as the application starts in the
current workspace before it is moved to the requested workspace.  I
expect you would need to add one of those rather than finding one in
RHEL4.

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: Please advise on bash programming tactics/strategy

2007-12-13 Thread Mike Stroyan
On Wed, Dec 12, 2007 at 06:49:25PM -0500, cga2000 wrote:
 On Wed, Dec 12, 2007 at 12:31:47AM EST, Bob Proulx wrote:
  cga2000 wrote:
   I was wondering if there is any way I can convince netstat to return
   its output to bash variables for additional processing.
  
  Do you mean like this?
  
  rxcnt=$(netstat -ni | awk '/^eth0/{print$4}')
 
   #!/bin/sh
 
   interface=eth0
 
   get_data()
   {
 netstat -ni | awk '/^'$interface'/{print$4,$8}'
   }
 
   init_data()
   {
 netdata=$(get_data)
 prevrxcnt=$(echo $netdata | awk '{print$1}')
 prevtxcnt=$(echo $netdata | awk '{print$2}')
   }
 
   save_data()
   {
 netdata=$(get_data)
 rxcnt=$(echo $netdata | awk '{print$1}')
 txcnt=$(echo $netdata | awk '{print$2}')
 diffrxcnt=$(($rxcnt - $prevrxcnt))
 difftxcnt=$(($txcnt - $prevtxcnt))
 prevrxcnt=$rxcnt
 prevtxcnt=$txcnt
   }
 
   init_data
   while sleep 1; 
   do
 save_data
 echo $diffrxcnt $difftxcnt | 
 awk '{printf %4.1f k/s %4.1f k/s\n,$1*576/1024,$2*567/1024}'
   done
 
   exit 0
 
 I provides exactly the output I need .. although bash must provide a 
 more elegant (and less expensive) way to split a variable that contains
 two fields separated by a space than invoking awk.

  You can use
 read rxcnt txcnt  $netdata
to split out the two values.

  You don't need awk for the splitting of netstat output into words.
The bash read command can do that.
This will split the lines into array a and examine each line.

get_data()
{
local a
netstat -ni |
while read -a a
do
if [[ ${a[0]} == $interface ]] 
then
echo ${a[3]} ${a[4]}
fi
done
}

Or this next version will split the lines into variables and examine them
for matches.  The d variable is a dummy placeholder for unused fields.
The last use of d variable gets the entire remainder of each line.

get_data()
{
local int d rxcnt txcnt
netstat -ni |
while read int d d rxcnt txcnt d
do
if [[ $int == $interface ]] 
then
echo $rxcnt $txcnt
fi
done
}

  It would be more modular to use an argument to get_data to pass
the interface instead of using the $interface global variable.

get_data()
{
local int d rxcnt txcnt target
target=$1
netstat -ni |
while read int d d rxcnt txcnt d
do
if [[ $int == $target ]] 
then
echo $rxcnt $txcnt
fi
done
}

Then you would invoke it as netdata=$(get_data $interface)

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: Problem with pattern replacing when STRING is an expandable char

2007-12-12 Thread Mike Stroyan

 Repeat-By:
 a=111.1
 echo ${a//[0-9]/x}

 correctly gives xxx.x, but

 echo ${a//[0-9]/*}

 gives a listing of files in current directory. Seems that the *
 is expanded before replacing the pattern.

 It workes the right way at least up to bash-3.1.17(1)-release

 But if you set

 a=111

 it doesn't even work in 3.1.17 right.

  The pathname expansion of * is not done until after the parameter
expansion substitution.  That is the documented behavior.  The following
example shows that echo of the ***.* pattern matches files and
directories that have a . in their name.  Setting a to 111 results
in a pathname pattern of *** that matches all of the files.
Double quoting the substitution prevents pathname expansion.

$ echo $BASH_VERSION
3.2.25(1)-release
$ touch a b c.d e.f
$ ls
a  b  c.d  e.f
$ a=111.1
$ echo ${a//[0-9]/*}
c.d e.f
$ echo ${a//[0-9]/*}
***.*
$ a=111
$ echo ${a//[0-9]/*}
a b c.d e.f
$ echo ${a//[0-9]/*}
***
$ 

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: SIGTTOU handling

2007-11-13 Thread Mike Stroyan
On Sun, Nov 11, 2007 at 09:56:11PM -0800, [EMAIL PROTECTED] wrote:
...
 I had some difficulties getting job control working at
 first.  I found that having the child process do a 
 setpgrp() before forking to the bash instance made the
 error message about disabling job control go away.

You need to call setpgrp or setsid and then open a pty device
to establish the pty as a control terminal.

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: how could I execute a set of script in a directoy tree?

2007-11-13 Thread Mike Stroyan
On Wed, Nov 14, 2007 at 01:38:01PM +0800, 龙海涛 wrote:
...
 but now what i want to do is write a shell script , call all the
 autotest.sh in every leaf-directory.

  You could do that with a recursive function that descends into
each directory.  Using ( ) around the cd to a subdirectory will
return to the previous directory at the closing parenthesis.
Looking for autotest.sh files in just leaf directories would be
harder than executing those files in all directories of the tree.
It would be possible to test for the presence of subdirectories
first and suppress execution of autotest.sh in non-leaf directories.
But I will assume that you don't actually require that.

r () 
{ 
cd $1
if [ -x autotest.sh ]; then
./autotest.sh;
fi;
for d in *
do
if [ -d $d ]; then
( r $d )
fi;
done
}

Then run
  r /testcase
to acutally use the recursive function on /testcase.

But the find command is very good at doing this as well.

 find /testcase -name autotest.sh -perm /111 -execdir bash -c ./autotest.sh \;

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: Looping through lines with tabs of file with cat

2007-11-04 Thread Mike Stroyan
On Sun, Nov 04, 2007 at 07:42:21AM -0800, yitzle wrote:
 How do I loop through the lines of a file when the lines have a tab in them?
 When I quote the cat operator, it reads the entire file at once.
 When I do not quote, each tab seperated item is treated as a new item.
 How do I make it seperate items by newline only?
 -- CODE --
 fileIn=blah
 for i in $(cat $fileIn)
 do
 echo $i
 echo
 done

  Don't use cat.  Read the contents of the file directly with read.

fileIn=blah
while read i
do
echo $i
echo
done  $fileIn

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: What does the ` Characteter Do?

2007-10-08 Thread Mike Stroyan
On Mon, Oct 08, 2007 at 01:59:25PM -0600, Bob Proulx wrote:
 duff wrote:
  What does this ` character do in the command line?
 
 Command Substitution.  And I was a little surprised to see that when I
 looked for that character in the man page that it did not appear
 anywhere within it in the Debian formatting of the manual.  It appears
 that there is a formatting issue surrounding the output of that
 character and this may have prevented you from finding that character
 by a search of the documentation.

  The ` character does format correctly on debian for some locales.
I get good output with 
  LANG=C man bash

  The problem comes from formatting of ` to an abstract 'left quote'
value.  That can be avoided by quoting it in the manual source as \`.
That is an understandable error.  Even man groff gets that wrong.

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: Readline history and bash's read -e

2007-09-02 Thread Mike Stroyan
On Sat, Sep 01, 2007 at 12:11:58AM +0100, Phil Endecott wrote:
 Dear Bash and Readline Experts,
 
 I have a simple shell script that reads user commands in a loop using
 read -e.  -e enables readline, but not its history feature.  Is there
 any way to get readline history with bash's read builtin?

Phil,

  You can use history -r to read a file into the shell's history
and history -s to add each line that you read into the history.
Then use history -w to save the history back to the file.  Here is
an example with vi style readline editing.

#!/bin/bash
history -r script_history
set -o vi
CMD=
while true
do
echo Type something
read -e CMD
history -s $CMD
echo You typed $CMD
case $CMD in
stop)
break
;;
history)
history
;;
esac
done
history -w script_history
echo stopping

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: recalculate LINES and COLUMNS

2007-08-22 Thread Mike Stroyan
On Mon, Aug 20, 2007 at 07:40:47AM +0200, thomas wrote:
 Sometimes I want to change the font of my terminal (urxvt): for
 instance, I am tired and want a bigger font. I can use a bash alias
 (or a keyboard shortcut) which runs these two lines:
 
 printf '\e]710;%s\007' 'xft:DejaVu Sans Mono:size=10'
 kill -WINCH $$
 
 Font is changed but the second line seems to have no effect: bash does
 not recompute the values of COLUMNS and LINES, thus I may type
 outside urxvt's window.
 
 There is a checkwinsize option but it does not seem to help.
 
 If I manually resize the window, the problem is fixed.
 
 How can I send a WINCH signal to bash so that it recalculates the
 correct values of LINES and COLUMNS after a font change?

  It works fine for me using rxvt-unicode 8.1 and bash 3.2.13(1) from
ubuntu 7.04.  If a urxvt window is maximized or grows large enough to exceed
the screen size, then the number of columns changes and $COLUMNS is
updated immediately without using any kill command.  (If the window is
not maximized and remains small enough fit the screen then the number of
lines and columns is not changed by the font change escape sequence.)

-- 
Mike Stroyan [EMAIL PROTECTED]




Re: need explanation ulimit -c for limiting core dumps

2006-10-20 Thread Mike Stroyan

I'm trying to limit the size of coredumps using 'ulimit -c'.  Can someone 
please explain why a core file gets generated from the coretest program (source 
is below)?

Thanks for any help or suggestions.

Shell interaction
% ulimit -H -c
unlimited
% ulimit -S -c
0
% bash --version
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.
% ulimit -c 512
% ulimit -S -c
512
% ulimit -H -c
512
% ./coretest 2048
rlim_cur,rlim_max = 524288,524288
malloced 2097152 bytes my pid is 21255
Segmentation fault (core dumped)
% ls -l core
-rw---  1 jacr swdvt 2265088 2006-10-19 14:24 core


Jason,

 This clearly is not a bash bug as your own program shows that getrlimit
reports the correct setting of 512K for RLIMIT_CORE.

 This is a kernel surprise.  The RLIMIT_CORE setting does not actually limit
the size of a core file as reported by ls -l.  It limits the size of
the core file
on disk as reported by du --si core.  Your coretest program used a large
malloc and did not actually touch the pages for that malloc.  So the core
dump created a sparse file with gaps at the pages that were never touched.
If you change c=malloc(sz); to c=calloc(sz,1); then you will see a core file
that is not sparse at all.  It will be reported as 512K bytes by both ls and du.
The RLIMIT_CORE effect for non-zero limits is to truncate large core
files rather
than prevent a core dump from happening.

 Sparse core files can cause trouble for the unwary.  They may become
non-sparse when copied.  That takes up more disk space.

--
Mike Stroyan
[EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Does HIGH_FD_MAX have to be so low?

2006-10-19 Thread Mike Stroyan
  I was recently helping to debug a problem with an application getting
bad file descriptor errors when run from a shell wrapper script.  The
cause was that the parent process left fildes 255 open for the child
process, but the bash wrapper script was causing fildes 255 to be
closed.

  Looking at open_shell_script() in shell.c and move_to_high_fd() in
general.c, I find that the code will force the use of fildes 255,
(HIGH_FD_MAX), for reading the shell script when getdtablesize() reports
that the maximum allowed file descriptor value is greater than 255.
In this particular case the maximum file descriptor value was 1023,
which would have stayed out of the way of the application's use.

  Does HIGH_FD_MAX need to be so low?  (OK.  255 isn't _REALLY_ low.)
Are there negative consequences for using a higher file descriptor when
getdtablesize() reports that they are allowed?

-- 
Mike Stroyan, [EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Does HIGH_FD_MAX have to be so low?

2006-10-19 Thread Mike Stroyan
On Thu, Oct 19, 2006 at 03:33:37PM -0400, Chet Ramey wrote:
 Mike Stroyan wrote:
 
Looking at open_shell_script() in shell.c and move_to_high_fd() in
  general.c, I find that the code will force the use of fildes 255,
  (HIGH_FD_MAX), for reading the shell script when getdtablesize() reports
  that the maximum allowed file descriptor value is greater than 255.
  In this particular case the maximum file descriptor value was 1023,
  which would have stayed out of the way of the application's use.
 
 If you look closely at move_to_high_fd(), you see that it attempts to
 avoid file descriptors already in use.  Only if fcntl(fd, F_GETFD, ...)
 returns -1 does it conclude that file descriptor fd is available.
 
 One can debate whether or not we should be checking explicitly for
 EBADF, but that's the only value of errno that's valid for F_GETFD
 anyway.
 
 I'd be interested in knowing why fcntl didn't return -1, if the parent
 process really did leave the file descriptor open and didn't set the
 close-on-exec flag.

  move_to_high_fd() only avoid open file descriptors if the
check_new parameter is non-zero.  open_shell_script() calls
move_to_high_fd() with a check_new value of 0.  The other two callers
of the function do pass in a check_new value of 1.

-- 
Mike Stroyan, [EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Does HIGH_FD_MAX have to be so low?

2006-10-19 Thread Mike Stroyan
On Thu, Oct 19, 2006 at 04:02:36PM -0400, Chet Ramey wrote:
 Mike Stroyan wrote:
 
move_to_high_fd() only avoid open file descriptors if the
  check_new parameter is non-zero.  open_shell_script() calls
  move_to_high_fd() with a check_new value of 0.  The other two callers
  of the function do pass in a check_new value of 1.
  
 
 Aha!  I missed the most relevant call.  Now the question is whether or
 not it's still a good idea to pass that 0 from open_shell_script.

  Forcing the reuse of an already open file descriptor does seem strange.
I can't think of a situation when that is likely to be better than
using a lower unopened file descriptor or just keeping the original file
descriptor returned by open.  If all callers will use a value of 1 you
could just eliminate the check_new parameter.

  Looking at the other callers, I noticed that the call to
move_to_high_fd() by process_substitute() is using a rather
low value for maxfd.

  parent_pipe_fd = move_to_high_fd (parent_pipe_fd, 1, 64);

  It will search for an unopened file descriptor between 4 and 64 then
take the highest one it can find.  If no file descriptor is unopened
in that range then it will keep using the original file descriptor
returned by pipe().  It doesn't ask to look nearly as high as the
other two callers of move_to_high_fd().  But it is not clear why it
is different.

-- 
Mike Stroyan, [EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: logout from interactive subshell

2006-10-12 Thread Mike Stroyan

Very often I do the following pattern:

   (1) rlogin to a foreign host
   (2) Invoke a subshell (for example because I'm setting a Clearcase
View)
   (3) Logout from the host

Step (3) needs two steps: First I have to type 'exit' to leave the
subshell,
and then either 'exit' or 'logout' to leave the login shell.

Is it possible to automate this in such a way that I have to type only
one command, to leave all subshells (in this case, only 1, but in
general, I might be several subshells deep) AND then logout?


 This shouldn't be a shell question at all.  It is an rlogin question.
Type ~. to make rlogin to close the connection.  The shells will
all exit in response to that.  (And you can do the same with ssh,
which you should be using instead of rlogin.)

--
Mike Stroyan
[EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: How to use [[ string =~ regexp ]]?

2006-05-21 Thread Mike Stroyan

On 5/21/06, Peter Volkov [EMAIL PROTECTED] wrote:


I have problems using =~ operator. I've tried to search for answer, but
failed. I'm using GNU bash, version 3.1.17. Can anybody give me some
examples of usage?

I really do not understand why

$ [[ string =~ [a-z] ]]  echo something
something

echo me something. IIUC the regular expression [a-z] matches any single
letter, so how string string matches one letter?


The =~ regexp match will match a substring by default.  You can use ^ and $
to anchor the expression to the start and end of the string.  You
won't get a match
with
[[ string =~ ^[a-z]$ ]]  echo match
But you will get a match with
[[ string =~ ^[a-z]{6}$ ]]  echo match
because it matches the correct number of characters.

--
Mike Stroyan
[EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: unwanted expansion of variable with nested strings

2006-05-04 Thread Mike Stroyan

A little more bash syntax can quote newlines for awk.

$ foo=a
b
c
$ lf=

$ gawk 'BEGIN {foo='${foo//$lf/\\n}'} END {print foo}' /dev/null
a
b
c

--
Mike Stroyan
[EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: comment

2006-04-09 Thread Mike Stroyan
 I have a question for you.
 How to comment a paragraph in bash file ?
 I read a lot of documentation and I dont find anything. May be I miss
 It but i need to know.

  There isn't a special convention for a paragraph comment.
You can start each line in your paragraph with a '#' character.
That is common practice.

# This is a
# multiline comment.

If you wanted to comment out several lines without adding a comment
character to each one, you could use a 'here' document with no command
to send it to.

\COMMENT
  This is a
  multiline comment.
COMMENT

It would be safer to quote a character in the here document delimiter as I did
above.  That will prevent command expansion of the comment text which might
have unintended side-effects.

--
Mike Stroyan
[EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Using variables in variables names

2006-03-13 Thread Mike Stroyan
On 3/13/06, Paul Jarc [EMAIL PROTECTED] wrote:
 Dirk H. Schulz [EMAIL PROTECTED] wrote:
  Paul Jarc schrieb:
  ac=12 eval dings$ac=wasannersder
 
  And how do I reference it then?

 ac=12 eval value=\$dings$ac
 echo $value

 Or:

 ac=12 name=dings$ac echo ${!name}

It seems that you need to use the eval form instead of the ${!var} form
to handle array variables.  Here are some examples I played with.  The
pattern is to use a backslash to quote the $ for the array name.  The $i
in the array examples could be done as \$i because it works out the same
if it is expanded in either the first pass or the second pass.

$ suffix=one
$ eval pre_${suffix}=simple1
$ suffix=two
$ eval pre_${suffix}=simple2
$ suffix=one
$ eval echo \$pre_${suffix}
simple1
$ suffix=two
$ eval echo \$pre_${suffix}
simple2
$ suffix=one
$ i=1
$ eval pre_A_${suffix}[$i]=array1_1
$ i=2
$ eval pre_A_${suffix}[$i]=array1_2
$ suffix=two
$ i=1
$ eval pre_A_${suffix}[$i]=array2_1
$ i=3
$ eval pre_A_${suffix}[$i]=array2_3
$ set | grep pre_
_='pre_A_two[3]=array2_3'
pre_A_one=([1]=array1_1 [2]=array1_1)
pre_A_two=([1]=array2_1 [3]=array2_3)
pre_one=simple1
pre_two=simple2
$ i=1
$ eval echo \${pre_A_${suffix}[$i]}
array2_1
$ eval echo \${pre_A_${suffix}[$i]}
array2_1
$ i=3
$ eval echo \${pre_A_${suffix}[$i]}
array2_3
$ i=2
$ suffix=one
$ eval echo \${pre_A_${suffix}[$i]}
array1_2

--
Mike Stroyan
[EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


edit-and-execute-command in non-posix vi editing mode fails with default editor

2006-03-10 Thread Mike Stroyan
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2
uname output: Linux hpstryn6 2.6.15-1-amd64-k8-smp #2 SMP Thu Feb 23 04:57:49 
UTC 2006 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 3.1
Patch Level: 0
Release Status: release

Description:
The default edit-and-execute-command behavior for non-posix vi
editing mode fails when EDITOR is not set.  It has changed from
using vi in 3.0 to trying to use 'editor' first in 3.1.  But it
fails to start an editor and just executes the unchanged command line.

Repeat-By:
Start bash
set -o vi
unset EDITOR
Type 'dateescv'
The date command is run without a chance to edit it.

Fix:
Remove an extra right parenthesis from bashline.c.

--- bash/bashline.c~2006-01-31 13:30:34.0 -0700
+++ bash/bashline.c 2006-03-09 12:32:24.0 -0700
@@ -800,7 +800,7 @@
command being entered (if no explicit argument is given), otherwise on
a command from the history file. */
 
-#define VI_EDIT_COMMANDfc -e \${VISUAL:-${EDITOR:-$(command 
-v editor || echo vi))}}\
+#define VI_EDIT_COMMANDfc -e \${VISUAL:-${EDITOR:-$(command 
-v editor || echo vi)}}\
 #define EMACS_EDIT_COMMAND fc -e \${VISUAL:-${EDITOR:-$(command -v 
editor || echo emacs)}}\
 #define POSIX_VI_EDIT_COMMAND  fc -e vi
 


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: edit-and-execute-command in non-posix vi editing mode fails with default editor

2006-03-10 Thread Mike Stroyan
On Fri, Mar 10, 2006 at 04:40:00PM -0500, Chet Ramey wrote:
 Mike Stroyan wrote:
...
  Remove an extra right parenthesis from bashline.c.
  
  --- bash/bashline.c~2006-01-31 13:30:34.0 -0700
  +++ bash/bashline.c 2006-03-09 12:32:24.0 -0700
  @@ -800,7 +800,7 @@
  command being entered (if no explicit argument is given), otherwise on
  a command from the history file. */
   
  -#define VI_EDIT_COMMANDfc -e \${VISUAL:-${EDITOR:-$(command 
  -v editor || echo vi))}}\
  +#define VI_EDIT_COMMANDfc -e \${VISUAL:-${EDITOR:-$(command 
  -v editor || echo vi)}}\
   #define EMACS_EDIT_COMMAND fc -e \${VISUAL:-${EDITOR:-$(command -v 
  editor || echo emacs)}}\
   #define POSIX_VI_EDIT_COMMAND  fc -e vi
 
 That's not in bash-3.1 as distributed.  It must have been added by
 Debian.
 
 Chet

  Oops.  Now I see the debian patch that caused it.  I'll file a report
against debian.  Thanks for the reality check.

-- 
Mike Stroyan, [EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: bash-3.0.16 fails to compile on HP-UX 11.11

2006-02-25 Thread Mike Stroyan
 Fix:
 Here's the diff of lib/sh/strftime.c between 3.0.16 and 3.0. Was this change 
 done for some version of HP-UX other than 11.11?
 *** bash-3.0.16/lib/sh/strftime.c   Wed Mar  3 22:13:23 2004
 --- bash-3.0/lib/sh/strftime.c  Sun Aug  8 22:21:26 2004
 ***
 *** 97,99 
   extern int daylight;
 ! #if defined(SOLARIS) || defined(mips) || defined (M_UNIX)
   extern long int timezone, altzone;
 --- 97,99 
   extern int daylight;
 ! #if defined(SOLARIS) || defined(mips) || defined (M_UNIX) || defined (HPUX)
   extern long int timezone, altzone;
 ***
That check for HPUX is not actually in the version from
http://ftp.gnu.org/gnu/bash/bash-3.0.tar.gz .  The strftime.c file is
identical between
3.0 and 3.0.16.  Your version of the 3.0 source has been changed somehow.
There is a special case for HPUX and timezone in the 3.1 version of that file.
Bash 3.1 builds fine for me on HP-UX 11.11.
--
Mike Stroyan
[EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: prompt with \[ \] corrupted by vi history search

2006-02-08 Thread Mike Stroyan
 My only concern is whether this patch also affects {non-,}incremental
 searches in emacs mode.  But it sure solves the display bugs of doing
 non-incremental searches in vi mode.  Thanks for the patch.

I don't tend to use emacs mode.  A few quick experiments
definitely show the prompt problem does occur with the
non-incremental-reverse-search-history (M-p)
feature in emacs mode.  The patch corrects that symptom as well.
I don't see any problem with the incremental search.  It doesn't
seem to ever try to incorporate the standard prompt.

-- 
Mike Stroyan, [EMAIL PROTECTED]


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash