Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Bash script, scp and path names with spaces

Options
  • 04-10-2012 2:53pm
    #1
    Registered Users Posts: 1,112 ✭✭✭


    Hi,
    I am writing a bash script to automate the installation of some software.
    The script has to connect to a file server using ssh, pull all the required files, update repositories with dependencies and finally install the software.

    So the plan is to use ssh-keygen to generate keys, use scp to get the know files from known paths, and I have all this working.

    For the software part they are stored in a directory path like
    /opt/sw/some_software_deliveries/some software 1.0 delivery 2012-10-01/, /opt/sw/some_software_deliveries/some software 1.0 delivery 2012-10-02/
    etc. which I have no control over.

    So I ssh to the server, do some jiggery pokery to get the name of the last delivery and I then return that to my script as a variable.
    I then need to use that variable in an scp command to copy the files from the file server to the local file system, and it fails because of spaces in the path.

    This is part of my script
    echo "Getting latest software delivery directory from server" 
    	latestSoftware=`ssh user1@xxx.xxx.x.x "ls /opt/sw/some_software_deliveries/ -t --group-directories-first | head -n 1"`
    
    	echo "latest software found is $latestSoftware, installing it now"
    	scp -r user1@xxx.xxx.x.x:""sw/some_software_deliveries/$latestSoftware"" /opt/sw_repo
    

    Again I have no control over the path names, so can't fix that.
    I have tried putting " around the path name, but no joy
    What is the best way of passing the path I need to the scp command.
    Any help appreciated
    Thanks


Comments

  • Registered Users Posts: 1,112 ✭✭✭Dacelonid


    oops, figured it out. Needed to escape my path with "' and '"


  • Registered Users Posts: 435 ✭✭doopa


    You should also be able to escape the space character using \


Advertisement