Re: Questions about commandline-args

2011-11-12 Thread Christopher Roy Bratusek
On Saturday 12 November 2011 02:02:01 Chris F.A. Johnson wrote:
 On Sat, 12 Nov 2011, Christopher Roy Bratusek wrote:
  On Friday 11 November 2011 19:32:51 Chris F.A. Johnson wrote:
  On Fri, 11 Nov 2011, Christopher Roy Bratusek wrote:
  Hi list,
  
  I've got a question about commandline args, imagine:
  
  personal_function ab{c,d}
  
  personal_function will receive abc and abd.
  Is there a way to make it receive ab{c,d}
  instead (without chaning the arguement itself)?
  
  Quote it: personal_function ab{c,d}
  
  Hmm.. right. But is there a way to achieve that without quoting?
 
 If it is not quoted, the shell will expand it before your script
 even sees it.
 
  Maybe some trap (just like for do X before bash exists)?
 
 If you are calling a function, bash already exists.

I meant exits, like:

trap 'printf %s $PWD  $HOME/.lastpwd' EXIT

signature.asc
Description: This is a digitally signed message part.


Re: invoke tilde expansion on quoted string

2011-11-12 Thread Geir Hauge
2011/11/12 Chris F.A. Johnson ch...@cfajohnson.com

 On Fri, 11 Nov 2011, Peng Yu wrote:

 I'm wondering if I already have a string variable, is there a bash
 native to do tilde expansion on it.

 var='~/..'
 cd $var#how to change this line?


  eval cd $var


I'd avoid eval as that could potentially do more than just expand the
tilde, depending on what other characters the var contains. I'd just
replace the ~ with $HOME using parameter expansion.

cd ${var/#~\//$HOME/}

-- 
Geir Hauge


Why complete doesn't print anything if it is called in a bash script?

2011-11-12 Thread Peng Yu
Hi,

It is strange to me why complete doesn't print anything when it is
called in a bash script. I must have misunderstood some fundamentals.
Does anybody know why? Thanks!

~$ cat main.sh
#!/usr/bin/env bash

. ~/.bashrc

complete

~$ ./main.sh
~$ complete |head
complete -F _kill kill
complete -F _renice renice
complete -F _smbpasswd smbpasswd
complete -F _postconf postconf
complete -F _ldapwhoami ldapwhoami
complete -F _ldapaddmodify ldapadd
complete -F _launchctl launchctl
complete -F _java java
complete -F _stream stream
complete -F _filedir_xspec oodraw


-- 
Regards,
Peng



Re: Why complete doesn't print anything if it is called in a bash script?

2011-11-12 Thread Andreas Schwab
Peng Yu pengyu...@gmail.com writes:

 It is strange to me why complete doesn't print anything when it is
 called in a bash script. I must have misunderstood some fundamentals.
 Does anybody know why? Thanks!

If complete does not print anything then there are no completions
defined.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
And now for something completely different.



Re: Why complete doesn't print anything if it is called in a bash script?

2011-11-12 Thread Peng Yu
On Sat, Nov 12, 2011 at 10:01 AM, Andreas Schwab sch...@linux-m68k.org wrote:
 Peng Yu pengyu...@gmail.com writes:

 It is strange to me why complete doesn't print anything when it is
 called in a bash script. I must have misunderstood some fundamentals.
 Does anybody know why? Thanks!

 If complete does not print anything then there are no completions
 defined.

The question is why. I have source my bashrc, as you can see there are
completions defined in the interactive shell.

-- 
Regards,
Peng



Re: implicit unset of a read-only function unsets the functions

2011-11-12 Thread Chet Ramey
On 11/11/11 11:20 AM, jens.schmid...@arcor.de wrote:

 Description:
   If there is a read-only function f, and no variable f,
   then you cannot unset function f with unset -f f, but
   you can unset it with unset f.
 
   Since f is read-only, it should not be possible to unset it
   either way.

Thanks for the report.  This will be fixed in the next release of bash.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Why complete doesn't print anything if it is called in a bash script?

2011-11-12 Thread Chet Ramey
On 11/12/11 10:41 AM, Peng Yu wrote:
 Hi,
 
 It is strange to me why complete doesn't print anything when it is
 called in a bash script. I must have misunderstood some fundamentals.
 Does anybody know why? Thanks!

Since complete happily shows completions when run from a shell script,
there must be code in your bashrc that prevents them from being
defined if the shell is not interactive.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Why complete doesn't print anything if it is called in a bash script?

2011-11-12 Thread Peng Yu
On Sat, Nov 12, 2011 at 10:18 AM, Chet Ramey chet.ra...@case.edu wrote:
 On 11/12/11 10:41 AM, Peng Yu wrote:
 Hi,

 It is strange to me why complete doesn't print anything when it is
 called in a bash script. I must have misunderstood some fundamentals.
 Does anybody know why? Thanks!

 Since complete happily shows completions when run from a shell script,
 there must be code in your bashrc that prevents them from being
 defined if the shell is not interactive.

Thank you for reminding me! That's indeed the case (shown below is
from the bashrc file).

case $- in
  *i*) [[ -f /opt/local/etc/bash_completion ]]  .
/opt/local/etc/bash_completion ;;
esac

-- 
Regards,
Peng



Re: invoke tilde expansion on quoted string

2011-11-12 Thread Eric Blake
On 11/12/2011 07:53 AM, Geir Hauge wrote:
 2011/11/12 Chris F.A. Johnson ch...@cfajohnson.com
 
 On Fri, 11 Nov 2011, Peng Yu wrote:

 I'm wondering if I already have a string variable, is there a bash
 native to do tilde expansion on it.

 var='~/..'
 cd $var#how to change this line?


  eval cd $var

 
 I'd avoid eval as that could potentially do more than just expand the
 tilde, depending on what other characters the var contains. I'd just
 replace the ~ with $HOME using parameter expansion.
 
 cd ${var/#~\//$HOME/}

Except that your proposed parameter expansion only works for plain ~.
It doesn't cover more useful tilde expansions, such as ~user/, which
does NOT expand to $HOME, but to user's home directory.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


'exec /dev/null' fails if ulimit -n 6

2011-11-12 Thread Paul Eggert
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-unknown-linux-gnu' 
-DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/cs/bash-4.2/share/locale' 
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g -O2
uname output: Linux lnxsrvg1.seas.ucla.edu 2.6.18-274.7.1.el5 #1 SMP Mon Oct 17 
11:57:14 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

Bash Version: 4.2
Patch Level: 10
Release Status: release

Description:
Bash can't do I/O redirection using 'exec' when operating
in an environment where all FDs above 10 are taken, even
if there are FDs available below 10.

This caused a coreutils test case to fail.  There is a
workaround, but the Bash bug should get fixed too.  See:
http://lists.gnu.org/archive/html/coreutils/2011-11/msg00036.html.

Repeat-By:
Run this command:

  bash -c 'ulimit -n 6; exec /dev/null  echo ok'

This should output ok, but instead it outputs:

  bash: redirection error: cannot duplicate fd: Invalid argument
  ./bash: /dev/null: Invalid argument

Running 'strace' indicates the following set of syscalls:

  setrlimit(RLIMIT_NOFILE, {rlim_cur=6, rlim_max=6}) = 0
  open(/dev/null, O_RDONLY) = 4
  fcntl(0, F_GETFD)   = 0
  fcntl(0, F_DUPFD, 10)   = -1 EINVAL (Invalid argument)
  fcntl(0, F_DUPFD, 10)   = -1 EINVAL (Invalid argument)
  write(2, ./bash: redirection error: canno..., 65./bash: redirection 
error: cannot duplicate fd: Invalid argument
  ) = 65

So, Bash is unnecessarily dup'ing file descriptor 0 to 10-or-more,
and then complaining because the dup fails.  But there is
no reason to dup here.




Re: Compile time bug with --enable-static-link option in configure

2011-11-12 Thread Chet Ramey
On 11/10/11 4:20 AM, raphael.grapi...@ac-poitiers.fr wrote:
 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-unknown-linux-gnu' 
 -DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/share/locale' 
 -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib  
 -D_GNU_SOURCE -DRECYCLES_PIDS -DSYSLOG_HISTORY  -g -O2
 uname output: Linux p**l 2.6.32-131.17.1.el6.x86_64 #1 SMP Thu Sep 29 
 10:24:25 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
 Machine Type: x86_64-unknown-linux-gnu
 
 Bash Version: 4.2
 Patch Level: 10
 Release Status: release
 
 Description:
   The computer I used to compil is a Vmware VM running RHEL 6.1 x64.
   I used this configure command :
   ./configure --with-bash-malloc=no --with-afs --enable-static-link
   and this make command :
   make CPPFLAGS=-D_GNU_SOURCE -DRECYCLES_PIDS -DSYSLOG_HISTORY `getconf 
 LFS_CFLAGS`
   Error output of gcc :
   l10nflist.c:64: erreur: static declaration of ‘stpcpy’ follows 
 non-static declaration
   
   gcc --version=gcc (GCC) 4.4.5 20110214 (Red Hat 4.4.5-6)
   
   I want a statically linked bash with the history logged through SYSLOG.
   It seems that configure doesn't complain.

The question is why HAVE_STPCPY is not defined by configure.  Check
config.h to see whether or not it's defined, and config.log to see
why if it's not.

Chet


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/