Results 1 to 9 of 9

Thread: #!/bin/sh script

  1. #1
    Funking Prink! Raz316's Avatar
    Join Date
    Jul 2003
    Location
    Deal, Kent, UK
    Posts
    2,978
    Thanks
    130
    Thanked
    62 times in 52 posts

    #!/bin/sh script

    Code:
    #!/bin/sh
    
    # Templates directory
    templatedir="/etc/e-smith/templates"
    # Current directory
    currentdir=`pwd`
    # Merge to previous directories to get a new one
    newdir=$templatedir$currentdir
    # Show the new directory
    echo $newdir
    # Change to it
    cd $newdir
    It doesn't change directory, any ideas? I'm not great at shell scripting so I could be going about this the wrong way.

    Cheers

  2. #2
    Goat Boy
    Join Date
    Jul 2003
    Location
    Alexandra Park, London
    Posts
    2,428
    Thanks
    0
    Thanked
    0 times in 0 posts
    How do you mean, it doesnt change directory? Try adding an "ls" a the bottom of the script. If you run that script. it probably wont change the directory of the session you run it in; it will create a new shell session, so it's probably changing directory ok and then just quitting...
    "All our beliefs are being challenged now, and rightfully so, they're stupid." - Bill Hicks

  3. #3
    Funking Prink! Raz316's Avatar
    Join Date
    Jul 2003
    Location
    Deal, Kent, UK
    Posts
    2,978
    Thanks
    130
    Thanked
    62 times in 52 posts
    ahh good point. It is changing it for its own session.

    How would I make it change my current session?

  4. #4
    Member
    Join Date
    May 2004
    Posts
    50
    Thanks
    0
    Thanked
    0 times in 0 posts
    Could you not just use "source <script>" to execute it withon your current shell ?

  5. #5
    Funking Prink! Raz316's Avatar
    Join Date
    Jul 2003
    Location
    Deal, Kent, UK
    Posts
    2,978
    Thanks
    130
    Thanked
    62 times in 52 posts
    maybe, never used that command before, ill give it a try tomorrow thanks.

  6. #6
    Goat Boy
    Join Date
    Jul 2003
    Location
    Alexandra Park, London
    Posts
    2,428
    Thanks
    0
    Thanked
    0 times in 0 posts
    or if you are running the bash shell, just run:

    . <script>
    "All our beliefs are being challenged now, and rightfully so, they're stupid." - Bill Hicks

  7. #7
    Agent of the System ikonia's Avatar
    Join Date
    May 2004
    Location
    South West UK (Bath)
    Posts
    3,736
    Thanks
    39
    Thanked
    75 times in 56 posts
    does the directory exist. if your cd'ing $newdir

    that would be "/etc/e-smith/templates/$your_current_working_dir" is that what you expected ?

    instead of cd'ing echo it and see where its taking you.

    also run set -x to get more output

  8. #8
    Senior Member
    Join Date
    Jun 2004
    Location
    Kingdom of Fife (Scotland)
    Posts
    4,991
    Thanks
    393
    Thanked
    220 times in 190 posts
    • crossy's system
      • Motherboard:
      • ASUS Sabertooth X99
      • CPU:
      • Intel 5830k / Noctua NH-D15
      • Memory:
      • 32GB Crucial Ballistix DDR4
      • Storage:
      • 500GB Samsung 850Pro NVMe, 1TB Samsung 850EVO SSD, 1TB Seagate SSHD, 2TB WD Green, 8TB Seagate
      • Graphics card(s):
      • Asus Strix GTX970OC
      • PSU:
      • Corsair AX750 (modular)
      • Case:
      • Coolermaster HAF932 (with wheels)
      • Operating System:
      • Windows 10 Pro 64bit, Ubuntu 16.04LTS
      • Monitor(s):
      • LG Flattron W2361V
      • Internet:
      • VirginMedia 200Mb
    Raz me man, what does you're echo statement tell you?

    Does this directory actually exist on the system that you're on?

    If you want to debug it a wee bitty easier, try "sh -x script" and it should give you an echoback of what it's doing.

    I figure from the fact that you're sh-ing rather than bash-ing that you're not on Linux. What OS are you on: Solaris; HP-UX; AIX ?

    (As long as it's not SCO !!!!)

    crossy
    (Happier with ksh than sh to be honest)

  9. #9
    Funking Prink! Raz316's Avatar
    Join Date
    Jul 2003
    Location
    Deal, Kent, UK
    Posts
    2,978
    Thanks
    130
    Thanked
    62 times in 52 posts
    ack! sorry everyone, totally forgot about this thread :/

    Could you not just use "source <script>" to execute it withon your current shell ?
    That solved it, ta deep!

    And the OS I was using is SME which requires you to edit the template files, instead of the actual file e.g.
    I goto /etc/ and want to edit the file resolv.conf..
    the files I actually want to edit are in the directory /etc/e-smith/templates/etc/resolv.conf/ so I run 'source customdir resolv.conf'

    customdir is...
    Code:
    #!/bin/sh
    
    templatedir="/etc/e-smith/templates"
    currentdir=`pwd`
    newdir=$templatedir$currentdir"/"$1
    echo $newdir
    cd $newdir
    thanks everyone

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. script of useful commands
    By robbiehall in forum Software
    Replies: 5
    Last Post: 08-08-2003, 06:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •