Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, Im a total novice with Linux and am trying to alter a script on an embbed linux board. Basically the script at the moment is.. cd /usr/bin arm-app So ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    2

    Simple Linux script.

    Hi,

    Im a total novice with Linux and am trying to alter a script on an embbed linux board.

    Basically the script at the moment is..

    cd /usr/bin
    arm-app

    So it changes directory and then runs our arm application.

    What I would like it to do is this.

    cd /usr/bin
    if FileExists ( Upgrade.tar) then
    uncompress to local directory ( overwrite )
    delete upgrade.tar
    end
    arm-app

    Im sure this is "bread and butter" to you wizards, but I really am struggling being a poor windows user.

    Appreciate any help you can give.

    Regards
    Ashley.

  2. #2
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    if FileExists ( Upgrade.tar) then
    uncompress to local directory ( overwrite )
    delete upgrade.tar
    end

    you are on about Bash Scripting?
    Since that looks like horrid Batch..

    try
    if(-e Upgrade.tar)
    tar -xvf Upgrade.tar
    rm Upgrade.tar
    fi
    New Users, please read this..
    Google first, then ask..

  3. #3
    Just Joined!
    Join Date
    Mar 2009
    Posts
    2

    Scripting

    Hi,

    Thanks for the help.

    I copied that into the file and get an error.

    ./test.sh: line 4: syntax error near unexpected token `fi'
    ./test.sh: line 4: `fi'

    Not to worry, I have had a look around the forum now and I see some other helpful chaps have linked to some handy scripting sites.

    Thanks.
    /Ash

  4. #4
    Just Joined!
    Join Date
    Feb 2009
    Posts
    45
    Quote Originally Posted by RobinVossen
    if(-e Upgrade.tar)
    tar -xvf Upgrade.tar
    rm Upgrade.tar
    fi
    Quote Originally Posted by tblue
    I copied that into the file and get an error.

    ./test.sh: line 4: syntax error near unexpected token `fi'
    ./test.sh: line 4: `fi'
    The correct syntax is:
    Code:
    #! /bin/sh
    cd /usr/bin;
    if [ -e Upgrade.tar ]; then
    	(tar -xf Upgrade.tar && rm Upgrade.tar) > /dev/null;
    fi
    Note: this code removes Upgrade.tar only if unpacking the file was successful. Furthermore it swallows any messages from both commands that are not delivered through the standard error output.

  5. #5
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    I was kinda thinking he could think for himself. Just giving a pointer
    New Users, please read this..
    Google first, then ask..

  6. #6
    Just Joined!
    Join Date
    Feb 2009
    Posts
    45
    Quote Originally Posted by RobinVossen
    I was kinda thinking he could think for himself. Just giving a pointer
    Iʼm sorry, I misunderstood your answer. I will try to keep things like that in mind for the future. As for my defense: Because the code wasnʼt explicitely marked as pseudo code, any future reader of this thread might misconceive it for actual code and get unneccessarily confused. A hint might be appropriate.

Posting Permissions

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