LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-28-2012, 08:42 AM   #1
puntino
Member
 
Registered: Sep 2006
Location: Italy
Distribution: Suse 10.1
Posts: 78

Rep: Reputation: 15
soft link


Hi,
I have a binary file in the folder
/opt/mybinaryFolder/mybinary
I want to create a soft link to "mybinary" in the
folder home/puntino.
In the folder home/puntino I executed the command
ln -s /opt/mybinaryFolder/mybinary mybinary
I get a softlink to mybinary (the code it is hereafter)
Code:
#!/bin/bash
scriptdir=`dirname $0`
export LD_LIBRARY_PATH=$scriptdir
$0.bin "$@"

however if I try the command
./mybinary from /home/puntino it doen't work
the first error message was
"./mybinary: line 4: ./mybinary.bin: No such file or directory
"
I don't have the file mybinary.bin but simple mybinary
so I corrected the last line in the former code
in $0 "$@"
when I execute again the command
./mybinary from home/puntino
it gets stuck.
Thank you in advance.
 
Old 03-28-2012, 08:55 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
of course it gets "stuck" you're creating an infinite loop!

sounds like you just want to NOT create that symlink in the first place. isn't the least confusing way to deal with this all?
 
Old 03-28-2012, 09:52 AM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Are you just trying to set LD_LIBRARY_PATH whenever you call mybinary?
If mybinary never moves from /opt/mybinaryFolder/, then why not just fix LD_LIBRARY_PATH in your shell startup script and then you can call mybinary without issue. Otherwise you'll need two scripts, mybinary_start and mybinary, where mybinary_start sets up LD_LIBRARY_PATH and then calls mybinary. The way you have it now, mybinary is calling itself, over and over and over again. Like acid_kewpie said, you're stuck in an infinite loop.
 
Old 03-28-2012, 12:41 PM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
Oh yes, that is an infinite loop:
Code:
#!/bin/bash
$0 "$@"
What is your original goal?
 
Old 03-29-2012, 05:07 PM   #5
puntino
Member
 
Registered: Sep 2006
Location: Italy
Distribution: Suse 10.1
Posts: 78

Original Poster
Rep: Reputation: 15
Thank you all.
What I just wanted to do it is to create a shortcut to a binary file
that allowed me to invoke mybinary.
Like in windows, I wanted the shortcut in my home directory
while the binary file is in an opt sub-folder.
I found that a possible way to do that is
using the ln -s command.
Is there any other way to do that ?
Thank you in advance
 
Old 03-29-2012, 06:08 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
I'd say a symlink is indeed what you would use. Optionally, you could use a hardlink, although only a symlink can refer to a target on a different partition
http://linux.die.net/man/1/ln
 
Old 03-30-2012, 03:11 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
Do you mean this?

Code:
#!/bin/bash
scriptdir=`dirname $0`
export LD_LIBRARY_PATH=$scriptdir
/opt/mybinaryFolder/$0 "$@"
You could use symbolic link instead (ln -s)
 
Old 03-30-2012, 03:13 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
why would they mean that?? that's mushing together two different directories into one nonexistent path.
 
Old 03-30-2012, 03:24 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
Quote:
Originally Posted by acid_kewpie View Post
why would they mean that?? that's mushing together two different directories into one nonexistent path.
He mentioned a shortcut to a binary, that is something what windows have. a similar thing could have been a little script invoking the real binary.
In unix we can have a symbolic link instead (I wrote instead, both of them together is not ok. But you are right, I mistyped, that should be basename $0)

Code:
#!/bin/bash
script=`basename $0`
scriptdir=`dirname $0`
export LD_LIBRARY_PATH=$scriptdir
/opt/mybinaryFolder/$script "$@"
 
Old 03-30-2012, 03:31 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you'd need to hardcode the path for LD_LIBRARY_PATH too

bett off just having a script like

cd /opt/where/ever
./myscript
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference Between Soft Link & Hard Link rajaniyer123 Solaris / OpenSolaris 16 09-30-2012 03:42 AM
create soft link and hard link in RHEL5 ramadas88 Linux - Server 6 09-15-2010 04:32 AM
about soft link mail2mphani Linux - Newbie 2 03-05-2009 02:20 PM
hard link and soft link varunrapelly Linux - Newbie 9 10-02-2008 07:05 AM
Soft Link and Hard Link Moataz Red Hat 1 04-25-2005 06:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration