This is a very useful command as it eliminates the need to continually type
|less after a command. Instead you just type
so command [parameters]
If you type the command and the resulting output is too long
you just hit the uparrow, home, type so and enter - it's really fast.
I have tried the following function which works _sometimes_ but sometimes not:
function so {
$* |less -I~
}
It seems the cases when it does not work have to do with calling aliases.
Most of the common commands I use use aliases to set up the options
for the ones I like.
In dos using the 4dos.com command processor I have a similiar command which
works every time:
alias so=%& | *list /s
Note in 4dos you don't enclose the alias in quotes and aliases can take
command line parameters unlike bash.
I've been banging on this problem on and off for some time, have read the docs
of course and several books on shell programming but just can't seem to get it
solved.
Surely many others have come up with solutions.
Thanks for any help you can give me.
Larry Alkoff N2LA
--
Larry Alkoff N2LA
My address is: larryalk is_at mindspring dot com
You may have to write your own shell. Aliases are evaluated on the
"command word", i.e., usually the first token in the command string. This
is then repeated, in case the alias-replacement contains an alias. Later
in the command-string processing, functions are evaluated.
So what you're trying to do falls outside the realm of shell command
processing. To use a shell-scripting solution is probably more of a
headache than I want to endure.
On the other hand, perhaps a better solution would be to map a keystroke
combination to place the string "|less" at the end of the command string.
bash uses "readline", which permits you to do key-bindings to character
strings. (See readline manpage.)
--
Dave Brown Austin, TX
>
> You may have to write your own shell.
Do you mean "write your own shell" as in writing something like bash itself
or writing a script file? I'm quite comfortable with writing scripts - if
it's re-writing bash that's quite above my level <g>.
> Aliases are evaluated on the
> "command word", i.e., usually the first token in the command string. This
> is then repeated, in case the alias-replacement contains an alias. Later
> in the command-string processing, functions are evaluated.
Thanks - I didn't know that aliases are evaluated first, then functions.
I thought it was the other way around.
That probably explains why my
so function { $* |less }
works when I do "so set" or "so cat filename"
using unaliased set and cat
but when I try a "so vdir" I get
bash: vdir: command not found
error.
Still the command so far is useful so long as I avoid aliased commands.
For some reason the command still fails even when I preceed the alias with
a backslash as in "so \vdir"
I would hate to think that something so easily done in dos (4dos)
cannot be done in Linux!
> So what you're trying to do falls outside the realm of shell command
> processing. To use a shell-scripting solution is probably more of a
> headache than I want to endure.
I have already tried various script files but nothing seems to work - yet.
I don't quite understand why this should be a headache.
>
> On the other hand, perhaps a better solution would be to map a keystroke
> combination to place the string "|less" at the end of the command string.
> bash uses "readline", which permits you to do key-bindings to character
> strings. (See readline manpage.)
I'm looking at readline but don't understand it yet at all.
I'm in Austin also (sw). Would you be available for discussion after I get up
to speed on readline?
Larry Alkoff
You could call this Perl script 'so':
#!/usr/bin/perl -w
my $cmd = join " ",@ARGV;
system("$cmd | less");
--
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
>
> You could call this Perl script 'so':
>
> #!/usr/bin/perl -w
> my $cmd = join " ",@ARGV;
> system("$cmd | less");
David thanks for this interesting perl script.
I'm not yet familiar with perl.
It worked fine using
so ls
but did not with vdir and dir.
I think that is because it uses the sh shell
and those functions are not defined.
How could I change the script so that it runs under bash
and my extensive list of aliases will work?
Thanks, Larry
I meant "write your own shell". Call it "lash" for Larry's Aliasing
SHell". That's what you gotta do if you don't like the other guy's rules.
> I would hate to think that something so easily done in dos (4dos)
> cannot be done in Linux!
There are several things that are easily done in dos that cannot be done
in Linux [as easily]. There are quite a few things easily done in Linux
that cannot be done in dos. As they say: "Vive la difference!"
For your possible interest I just got this nifty function
from William McVey of CTLUG right here in Austin
function so {
eval "$@" |less -I~
}
It's working just fine so far, including with my aliases.
Best, Larry Alkoff Austin TX
Even when I tried to execute the command under bash, it did not seem to
interpret aliases in a non-interactive shell. But Perl can do anything if
you set your mind to it. I just needed to get the aliases from bash and
translate:
#!/usr/bin/perl -w
$ENV{BASH_ENV} = "$ENV{HOME}/.bashrc";
@alias = `bash -c alias`;
chomp @alias;
foreach $alias (@alias) {
$alias =~ s/alias //;
($name,$value) = split /=/, $alias;
$value =~ s/^('|")//; $value =~ s/('|")$//;
if ($ARGV[0] eq $name) {
die "$value\n" if $value =~ s/echo //;
shift @ARGV; unshift @ARGV,$value;
last;
}
}
exec "bash -c \"@ARGV\" | less";
> Even when I tried to execute the command under bash, it did not seem to
> interpret aliases in a non-interactive shell. But Perl can do anything if
> you set your mind to it. I just needed to get the aliases from bash and
> translate:
>
> #!/usr/bin/perl -w
> $ENV{BASH_ENV} = "$ENV{HOME}/.bashrc";
> @alias = `bash -c alias`;
> chomp @alias;
> foreach $alias (@alias) {
> $alias =~ s/alias //;
> ($name,$value) = split /=/, $alias;
> $value =~ s/^('|")//; $value =~ s/('|")$//;
> if ($ARGV[0] eq $name) {
> die "$value\n" if $value =~ s/echo //;
> shift @ARGV; unshift @ARGV,$value;
> last;
> }
> }
> exec "bash -c \"@ARGV\" | less";
David is there any way to filter out the escape sequences which clutter up the
screen with commands that use color?
Example: so dir
where dir is aliased to
alias dir='ls -l --color=auto'
This gives ESC followed by the sequence in black with white background before
and after each filename.
Regards, Larry