Using links with wildcards in bash.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using links with wildcards in bash.
# 1  
Old 09-07-2009
Using links with wildcards in bash.

I wrote a script using softlinks with wildcards and found out that it causes ambiguity.
I found an inelegant workaround but still don't understand how the ambiguity is caused.

Code:
.......
mkdir -p FtE/lib
pushd FtE >/dev/null
mkdir bin blks doc etc rdl sim sw syn tb
ln -s $DATASOURCE/SCs/synopsys/*.lib lib/.
popd >/dev/null

echo -e "Please insert the project name:"
read PROJECT
.......
.......
mkdir -p soc/Lib
pushd soc >/dev/null

#ln -s ../../FtE/lib/* Lib/.
#ln -s ../../FtE/lib/*.lib Lib/.
for LINKS in `ls ../FtE/lib`
do
ln -s ../../FtE/lib/$LINKS Lib/.
done

popd >/dev/null
.......
The green codes shows what worked. The brown code shows those that failed.
In the first green line, I used a wildcard (*) with 'ln -s' and it is accepted.
The next time I tried this, it fails so I have to use a 'for' loop.
Can anyone clarify what the ambiguity is here?

Last edited by cop02ia; 09-07-2009 at 11:59 PM..
# 2  
Old 09-10-2009
How did they fail? Was there an error message?
# 3  
Old 09-10-2009
Unfortunately no messages.
Probably because the wildcard (*) symbol was used, the softlinks were not created silently (no errors).
I found out from a different post (which was posted sometime ago) that it probably was caused by ambiguity.
https://www.unix.com/shell-programmin...-links-ln.html
so I'm wondering if someone could elaborate on this matter.


Sorry, my bad.
There was a wrong link created...
In my directory, instead of creating links to all the files, it created a file called:
"*" linking to "../../FtE/lib/*" OR "*.lib" linking to "../../FtE/lib/*.lib"

Here's how it looks with ls -lh:

lrwxrwxrwx 1 cad cad 24 Sep 11 2009 *.lib -> ../../FtE/lib/*.lib

Last edited by cop02ia; 09-10-2009 at 09:14 PM.. Reason: additional info. / correction
# 4  
Old 09-14-2009
I that seems normal when there are no files that match the first parameter, so you should probably test for their existence before attemping to symlink.

Personally I'd stick with the for loop since it's safer and more portable.
# 5  
Old 09-14-2009
I see.
Seems like I might have made a mistake in when popping/pushing directories around.
Well, it's a bit too late to backtrack & pinpoint now. I might as well stick to full directory paths & use 'for' loops to be safer.
Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. AIX

List all the soft links and hard links

Hi I'm logged in as root in an aix box Which command will list all the soft links and hard links present in the server ? (2 Replies)
Discussion started by: newtoaixos
2 Replies

2. Solaris

Hard Links and Soft or Sym links

When loooking at files in a directory using ls, how can I tell if I have a hard link or soft link? (11 Replies)
Discussion started by: Harleyrci
11 Replies

3. UNIX for Advanced & Expert Users

Wildcards

These 2 websites do a GREAT job of explaining different types of wildcards. I learned about the categories of characters which I never knew about at all. GNU/Linux Command-Line Tools Guide - Wildcards GREP (1 Reply)
Discussion started by: cokedude
1 Replies

4. UNIX for Dummies Questions & Answers

wildcards NOT

Hi All Please excuse another straightforward question. When creating a tar archive from a directory I am attempting to use wildcards to eliminate certain filetypes (otherwise the archive gets too large). So I am looking for something along these lines. tar -cf archive.tar * <minus all *.rst... (5 Replies)
Discussion started by: C3000
5 Replies

5. Shell Programming and Scripting

Symbolic Links - BASH Script

Hi all, This is my first message in this forum. I'd like to know if there is a nice way to get the complete path from a symbolic link. Example: When I do a ls -ltr I see this output. lrwxr-xr-x 1 mmmm users 66 Sep 4 09:58 LINK_SEND ->... (4 Replies)
Discussion started by: rodrimuino
4 Replies

6. UNIX for Dummies Questions & Answers

ls with wildcards

ok, I'm trying to write a script file that lists files with specific elements in the name into a txt file, it looks like this ls s*.dat > file_names.txt can't figure out whats wrong with that line, any ideas? thanks in advance (10 Replies)
Discussion started by: benu302000
10 Replies

7. UNIX for Dummies Questions & Answers

wildcards

when writing a shell script (bourne) and using a unix command like 'ls' is there anything special you need to do to use a wildcard (like *)? (3 Replies)
Discussion started by: benu302000
3 Replies

8. UNIX for Dummies Questions & Answers

Wildcards in VI

I'm trying to delete lines from a large text file using VI. Every line that I am wanting to delete start with 'S' - all others do not. (A list of users) I've tried using * but doesn't seem to like it...any ideas... Doesn't have to be VI - but I'm better with VI than sed/awk. (8 Replies)
Discussion started by: peter.herlihy
8 Replies
Login or Register to Ask a Question