Reputation: 893
So far "ls
" works fine i take all files in the directory. But now i want when i execute ./myscript ls -l /somedir
to take the same results as i take when i type ls -l /somedir
at the terminal.
Is there any way to make it? This is my code so far..
#!/bin/sh
clear
echo ""
read -p "type something : " file
echo""
IFS=:
for dir in $PATH ; do
if [ -x "$dir/$file" ]
then
echo ""
exec "$dir/$file"
fi
done
Upvotes: 0
Views: 105
Reputation: 295291
As I understand it (which involves a great deal of guesswork, as the question is not clearly asked), your problem is that command-line arguments aren't passed through.
Use "$@"
to access them:
#!/bin/bash
prog=$1; shift
IFS=: read -r -a paths <<<"$PATH"
for path in "${paths[@]}"; do
[[ -x $path/$prog ]] && "$path/$prog" "$@"
done
Then, running yourscript ls -l /foo
will actually pass the -l
and the /foo
through to any instance of ls
they create.
Upvotes: 2