LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Make multiples links with of a script with a PARAMETER (http://www.linuxquestions.org/questions/programming-9/make-multiples-links-with-of-a-script-with-a-parameter-948498/)

Trotel 06-04-2012 02:17 PM

Make multiples links with of a script with a PARAMETER
 
Hi, I try to make several links (of all files in /program/bin/* ) in one location (/usr/local/bin) in one step, to do that I create a script "links"

I try this, and that work

PHP Code:

#!/bin/bash 
cd /usr/local/bin
echo -
"Write the path" 
read path 
for i in my $path 
do 
t=${i##*/} 
ln -"$i" "${t%.*}" 
done 

The problem is when I write the path, it don't work with tab, and I use this script a lot of time and I prefer that it use tab. I want to add a parameter (ex. -path), like this:

Code:
./links -path /program/bin/*
How can I do that?

Thanks

theNbomr 06-04-2012 03:53 PM

Try
Code:

#
#  'path' is a poor choice, as it already has a special meaning...
read -e somepath

Google 'bash read tab completion' for several sites with illuminating information.

--- rod.

Trotel 06-05-2012 09:13 AM

Quote:

Originally Posted by theNbomr (Post 4695471)
Try
Code:

#
#  'path' is a poor choice, as it already has a special meaning...
read -e somepath

--- rod.

Thanks, that work.

David the H. 06-05-2012 03:10 PM

To expand on the solution, the -e option makes read use the readline library, which is what provides things like tab completion and key shortcuts. See the bash man page for more details on readline (and read).


Quote:

Originally Posted by theNbomr (Post 4695471)
# 'path' is a poor choice, as it already has a special meaning...

Umm, "PATH" has a special meaning. I'm not aware of "path" matching anything in particular. ;)

theNbomr 06-05-2012 07:27 PM

Yes, my bad. It does have a meaning in c-shell, but of course this is not c-shell. I still wouldn't choose a name with the same spelling in a different case. Some opinions differ.
--- rod.


All times are GMT -5. The time now is 01:34 PM.