•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 423,514 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,618 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 626 | Replies: 2 | Solved
![]() |
•
•
Join Date: Nov 2007
Posts: 118
Reputation:
Rep Power: 1
Solved Threads: 0
first of all, what can i do to make my command works like the "ls, cp, mv" ?
I always do vi myScript.sh and then chmod +x myScript.sh and I have to execute it like ./myScript.sh ,,, simply typing $myScript at the command promp will not work.
Second question for shell scripting:
I am trying to search whatever the argument is within only the user path... did I do this correctly? Thanks
my ideal output would be
> search ls
>/bin/ls something like that
I always do vi myScript.sh and then chmod +x myScript.sh and I have to execute it like ./myScript.sh ,,, simply typing $myScript at the command promp will not work.
Second question for shell scripting:
I am trying to search whatever the argument is within only the user path... did I do this correctly? Thanks
PATH=/bin:/usr/bin/:sbin/.
for command in PATH
do
grep "$1"
done my ideal output would be
> search ls
>/bin/ls something like that
•
•
Join Date: Apr 2008
Posts: 39
Reputation:
Rep Power: 1
Solved Threads: 8
In order just to type the name of the file to execute, it needs to be in an executable directory - so for e.g. if you have a script that is used frequently, drop it in /usr/local/bin and it will become executable from anywhere. You can also add the current directory as an executable path with:
[code]
PATH=${PATH}
PWD
[code]
However, please note that this can be extremely dangerous - because then any script in the current directory can accidentally be run.
I'm not quite sure what your second question is getting at. It sounds like you are trying to recreate the "which" command.
If you type which ls it will tell you which ls your local environment executes.
In order to recreate this, you would have to delimit the user's path variable:
Unlike which, this will return all installed instances (in your path) - the which command will only return the first instance found, which is the program that would actually be executed on your system.
[code]
PATH=${PATH}
PWD[code]
However, please note that this can be extremely dangerous - because then any script in the current directory can accidentally be run.
I'm not quite sure what your second question is getting at. It sounds like you are trying to recreate the "which" command.
If you type which ls it will tell you which ls your local environment executes.
$ which ls /bin/ls
In order to recreate this, you would have to delimit the user's path variable:
command=$1 for path in `echo $PATH | sed "s/:/ /g"` do ls $path | grep $command done
Last edited by omrsafetyo : Jun 27th, 2008 at 10:56 pm.
•
•
Join Date: Nov 2007
Posts: 118
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
In order just to type the name of the file to execute, it needs to be in an executable directory - so for e.g. if you have a script that is used frequently, drop it in /usr/local/bin and it will become executable from anywhere. You can also add the current directory as an executable path with:
[code]
PATH=${PATH}PWD
[code]
However, please note that this can be extremely dangerous - because then any script in the current directory can accidentally be run.
I'm not quite sure what your second question is getting at. It sounds like you are trying to recreate the "which" command.
If you type which ls it will tell you which ls your local environment executes.
$ which ls /bin/ls
In order to recreate this, you would have to delimit the user's path variable:
Unlike which, this will return all installed instances (in your path) - the which command will only return the first instance found, which is the program that would actually be executed on your system.command=$1 for path in `echo $PATH | sed "s/:/ /g"` do ls $path | grep $command done
thanks alot... yes, i was writing my own version of the which. I have one more question and i think i can get it done. I'll post the code in another thread. Thanks for the help again.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Shell Scripting Forum
- Previous Thread: Gathering data from specific lines
- Next Thread: unix little quiz


Linear Mode