Small Shell Script for ln -s

  • Hey Guys,


    iam trying to write a little shellscript that simply does the following:


    create symlink in one folder e.g.:


    Zitat

    "/media/UUID/Series2013/"


    called:


    Zitat

    "Series with spaces in the title"


    that points to:


    Zitat

    "/media/UUID/Series/subdirectory/Series with spaces in the title"


    the folder "subdirectory" can be one of the five following:

    Zitat

    0-C
    D-L
    M-R
    S-T
    U-Z


    If iam doing it manually with escaping characters by using "" the link gets created.


    Code
    root@omv-nas:~# ln -s "/media/d3c21c66-af4b-41d4-b098-462e83fa641d/Serien/test 123" "/media/d3c21c66-af4b-41d4-b098-462e83fa641d/ASerien/test 123"
    root@omv-nas:/media/d3c21c66-af4b-41d4-b098-462e83fa641d/ASerien# ls -l
    insgesamt 0
    lrwxrwxrwx 1 root root  22  3. Apr 17:05 Friends -> ../Serien/D-L/Friends/
    lrwxrwxrwx 1 root root  35  3. Apr 17:08 How I Met Your Mother -> ../Serien/D-L/How I Met Your Mother
    lrwxrwxrwx 1 root root  59  3. Apr 17:58 test 123 -> /media/d3c21c66-af4b-41d4-b098-462e83fa641d/Serien/test 123


    The Links for Friends and How I Met Your Mother were created within /media/d3c21c66-af4b-41d4-b098-462e83fa641d/ASerien/, so i just pointed them the directory upwards to their respective directorys within Serien/subdirectory/...


    However, if iam using a script like that, it does not escape the spaces correctly.: (yes it is in german, and yes atm it is just poiting to the directory "Series'")


    Bash
    #!/bin/sh
    # Script zum hinzufuegen von Softlinks
    
    
    cd /media/d3c21c66-af4b-41d4-b098-462e83fa641d/Serien/
    ln -s "$@" /media/d3c21c66-af4b-41d4-b098-462e83fa641d/ASerien/$@
    echo "Softlink fuer Serie $@ erfolgreich angelegt!"


    Purpose of this script or the Softlinks is, that i have an extra share for the Series' that are actually running Episodes or iam "rerunning/watching" at the moment. (Much easier for Media Boxes just to need to scroll through some Series' and not all of them)


    Can anybody help me how to correctly escape the spaces in that case?
    And it would be nice if the Script would automatically detects the right folder for the Series, but that would'nt be neccessary, as i could simply use 5 scripts, one for each directory.


    Greetings
    David

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • Nevermind, i got it:



    Code
    root@omv-nas:/home/david# ./3add.sh "The Big Bang Theory"
    ln -s /media/d3c21c66-af4b-41d4-b098-462e83fa641d/Serien/S-T/The Big Bang Theory /media/d3c21c66-af4b-41d4-b098-462e83fa641d/ASerien/The Big Bang Theory
    root@omv-nas:/home/david# ls /media/d3c21c66-af4b-41d4-b098-462e83fa641d/ASerien/
    The Big Bang Theory
    root@omv-nas:/home/david# ls /media/d3c21c66-af4b-41d4-b098-462e83fa641d/ASerien/ -la
    insgesamt 0
    drwxrwxr-x 2 root users 32  3. Apr 20:02 .
    drwxr-xr-x 5 root root  45  3. Apr 20:01 ..
    lrwxrwxrwx 1 root root  74  3. Apr 20:02 The Big Bang Theory -> /media/d3c21c66-af4b-41d4-b098-462e83fa641d/Serien/S-T/The Big Bang Theory
    root@omv-nas:/home/david#

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!