Home » Questions » Computers [ Ask a new question ]

Bash: overridding ls -la with ls -la | more (basic bash scripting problem)

Bash: overridding ls -la with ls -la | more (basic bash scripting problem)

Pretty new to bash scripting. Trying to over ride the ls -la command to be: ls -la | more

Asked by: Guest | Views: 225
Total answers/comments: 2
Guest [Entry]

"I can't reproduce this on Bash-3.00.16 on Solaris 10 or Cygwin, but it looks like your bash is parsing line 158 as an invocation of the ls command, and not as a function definition.

The ""function"" prefix is optional, but if it makes your bash accept the definition, then it's a reasonable workaround.
It doesn't alter the meaning of the function in any way.

Incidentally, which OS and Bash version are you using ?

uname -a
bash --version"
Guest [Entry]

"replace with:

function ls
{
if [[ $@ == ""-la"" ]]
then
echo ""test""
/bin/ls -la | more
else
/bin/ls ""$@""
fi;
}

Note: you'll need to reference the absolute path to the actual ls command inside the if or that'll reinvoke the same function and.... stackoverflow! :-)

EDIT: Yes, the command key word is a better way of preventing alias lookups."