Friday, May 3, 2024
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 2037  / 1 Year ago, thu, april 20, 2023, 7:43:13

I'm at a Hackathon right now so if someone would answer this soon, you'd be doing me a huge favor.



I've written a function called ls() in my .bashrc that looks like this:



ls() {

if(some condition);
do something
else
ls; #(CALL TO ORIGINAL ls SYSTEM CALL)
fi

}


But here when it goes to the else part, it just enters an infinite loop



How can I call the original ls system call in else
Or, how can I make ls behave differently in one folder and normally in the others.


More From » command-line

 Answers
7

You are looking for command:




command [-pVv] command [arg ...]



Run command with args suppressing the normal shell function lookup. Only builtin commands or commands found in the PATH
are executed. If the -p option is given, the
search for command is performed using a default value for PATH that is guaranteed to find all of the standard
utilities. If either the -V or -v option is supplied, a
description of command is printed. The -v option causes a single word indicating the command or file name used to
invoke command to be displayed; the -V option pro‐
duces a more verbose description. If the -V or -v option is supplied, the exit status is 0 if command was found, and 1
if not. If neither option is supplied and an
error occurred or command cannot be found, the exit status is 127. Otherwise, the exit status of the command builtin is
the exit status of command.




Example:



$ pwd() {
> echo 'command test'
> command pwd
> }
$ pwd
command test
/etc


There is also builtin, which is more restrictive:




builtin shell-builtin [arguments]



Execute the specified shell builtin, passing it arguments, and return its exit status. This is useful when defining a
function whose name is the same as a shell
builtin, retaining the functionality of the builtin within the function. The cd builtin is commonly redefined this way.
The return status is false if shell-builtin
is not a shell builtin command.



[#30715] Saturday, April 22, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irripri

Total Points: 164
Total Questions: 111
Total Answers: 107

Location: South Georgia
Member since Sun, Aug 8, 2021
3 Years ago
;