Jump to content

Having trouble with creating symlinks using shell script


Go to solution Solved by sKunKbad,

Recommended Posts

I'm having trouble with creating symlinks using a shell script. They end up being broken (dangling) unless I use the full path, but I'd like to make this script semi-portable.

 

I'm over-simplifying this:

#!/bin/bash

if [ ! -f ./lib/electro.php ]; then
	ln -s ./source/lib/electro.php ./lib/electro.php 
fi

This script is called .install.sh, and is located at ./source/scripts/.install.sh

 

So I go to my terminal, cd to where ./ would reference and run:

skunkbad: /var/www/example/application$ ./source/scripts/.install.sh

The script does end up creating the symlink in the proper location, but it's a broken link.

 

If I list the directory, it will look something like this:

lrwxrwxrwx  1 skunkbad www-data   51 Jun 26 17:40 electro.php -> ./source/lib/electro.php

But it's colored red, which is broken / dangling and it doesn't work.

 

My installer script will work as expected if I use an absolute path. What am I doing wrong? Should I somehow insert the absolute path as the script runs?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.