Misleading text at start of manual

2012-04-04 Thread Reuben Thomas
(Checked against bash 4.2; for some reason, the manual on gnu.org is only 4.1.)

The top node, "Bash Features", says:

"The following menu breaks the features up into categories based upon which
one of these other shells inspired the feature."

But the following menu doesn't seem to bear that out. Perhaps it's
simplest just to remove this sentence, as the top-level menu is
perfectly logical and self-explanatory.

-- 
http://rrt.sc3d.org



Re: Expanding aliases to full command before execution

2012-04-04 Thread dethrophes

Am 04.04.2012 17:27, schrieb jrrand...@gmail.com:

On Tue, Apr 3, 2012 at 5:22 PM, jrrand...@gmail.com  wrote:

Hi everyone,

In bash, is it possible to expand my aliases either before they are executed
or when they are stored in the history file?
For example, if I have:  alias ll='ls -l'  defined in my .bashrc, when I
execute "ll" from the command line, I'd like my history file to contain "ls
-l".  Is there any way to accomplish this?

Thanks,
Justin


I seem to have constructed a solution to my own problem.  I wrote a
function that creates the desired behavior for me and saves it in
$expanded if the argument was in fact an alias.

function expand_alias() # expand an alias to full command
{
 if [ "$1" = "." ]; then
 argument="\\$1"
 else
 argument="$1"
 fi
 match=$( alias -p | grep -w "alias $argument=" )
 if [ -n "$match" ]; then
 expanded="`echo $match | sed -e s/[^=]*=// | sed 's/^.\(.*\).$/\1/'`"
 else
 expanded="$1"
 fi
}


Thanks,
Justin


or you could just do

function expand_alias() # expand an alias to full command
{
if expanded=$( alias "${1}" ); then
expanded="${expanded#*=}"
else
expanded="$1"
fi
}

though depending on what your actually trying to do you'd be getter of 
using type, as not all aliases are aliases a lot are functions these days.




case $(type -t "$c") in
  "")
echo No such command "$c"
return 127
;;
  alias)
c="$(type "$c"|sed "s/^.* to \`//;s/.$//")"
;;
  function)
c=$(type "$c"|sed 1d)";\"$c\""
;;
  *)
c="\"$c\""
;;
esac

bash -xvc "$c"



Re: Expanding aliases to full command before execution

2012-04-04 Thread Linda Walsh



jrrand...@gmail.com wrote:


function expand_alias() # expand an alias to full command
{
if [ "$1" = "." ]; then
argument="\\$1"
else
argument="$1"
fi
match=$( alias -p | grep -w "alias $argument=" )
if [ -n "$match" ]; then
expanded="`echo $match | sed -e s/[^=]*=// | sed 's/^.\(.*\).$/\1/'`"
else
expanded="$1"
fi
}

---

I could see this being an option, because I can think of times I might want one 
or the other...


I might want to know exactly what I typed, (if only to remind me to use an alias 
for some long string and save on RSHP (Repetitive-Stress Hit-Points);


But at the same time it would be useful to know what alias(es) were in effect
at the time... (if only the alias was listed!)

so maybe a literal version, followed by (for lines that were 'expanded' by:

"["  "]"

Of course the same problem arises with 'functions' as they are said to replace 
aliases in _almost_ every situation.  I.e. do you really want your history file

to be different depending on whether you did
alias ll=ls\ -l
or
function ll { ls -l "$@"}
??
Wouldn't they have a similar effect on the accuracy of your record?

Of course, then my idea of literal expansion would get very messy... providing
a practical reason to not do it for functions... (depends on what your 
requirements are )... ;-)








Re: weird behavior of set -e

2012-04-04 Thread Linda Walsh



mhenn wrote:


Am 24.06.2011 11:51, schrieb Harald Dunkel:

Hi folks,

A colleague pointed me to this problem: If I run
( set -e; ( false; echo x ) )
in bash 4.1.5, then there is no screen output, as
expected. If I change this to
( set -e; ( false; echo x ) || echo y )
then I get "x" instead of "y". How comes?
Any helpful comment would be highly appreciated.

Harri



Hey Harald,
Thus, "false" is executed, but the command sequence is not cancelled
because of the "||". Then, after the ";" "echo x" is executed, which
gives a 0 exit status, which leads to "echo y" never to be executed
because of evaluation shortcut of "||". For this, see also:

man bash | less -p 'The \&\&'


---

Has this behavior changed in more recent versions?

The above description seems to be rather non-intuitive, given that ( ) should
mean it is evaluated in a sub-shell process, -- thus whether or not it aborts
after 'false', should be independent of the context.

If it was (set -e; { false ; echo x;} || echo y )
Then I could see {} being a type of parenthesis that allows evaluation
linearly, in the same process and would honor such dependencies.

Or is it the case that the "false;echo x", isn't executed in it's own separate 
process?


Of course who knows what it does now with the seeming concerted effort to kill
any use or usefulness for the -e switch...(sigh)...

perl has -w and use strict;  If you don't want -e to do it, maybe the 
"language"** should offer alternatives.


**-- I suppose that's the rub -- is it a language as in programming language,
or is it just supposed to be for the most primitive scripting needs.
Adding integers, arrays and hashes sure makes it seem more like a language than
the latter.









Re: Expanding aliases to full command before execution

2012-04-04 Thread jrrand...@gmail.com
On Tue, Apr 3, 2012 at 5:22 PM, jrrand...@gmail.com  wrote:
> Hi everyone,
>
> In bash, is it possible to expand my aliases either before they are executed
> or when they are stored in the history file?
> For example, if I have:  alias ll='ls -l'  defined in my .bashrc, when I
> execute "ll" from the command line, I'd like my history file to contain "ls
> -l".  Is there any way to accomplish this?
>
> Thanks,
> Justin
>

I seem to have constructed a solution to my own problem.  I wrote a
function that creates the desired behavior for me and saves it in
$expanded if the argument was in fact an alias.

function expand_alias() # expand an alias to full command
{
if [ "$1" = "." ]; then
argument="\\$1"
else
argument="$1"
fi
match=$( alias -p | grep -w "alias $argument=" )
if [ -n "$match" ]; then
expanded="`echo $match | sed -e s/[^=]*=// | sed 's/^.\(.*\).$/\1/'`"
else
expanded="$1"
fi
}


Thanks,
Justin