Skip to content

Instantly share code, notes, and snippets.

@klang
Created December 11, 2015 08:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klang/e73107562cf83031dc6e to your computer and use it in GitHub Desktop.
Save klang/e73107562cf83031dc6e to your computer and use it in GitHub Desktop.
An easy way to specify a destination as a single input parameter and still be able to get the individual data elements back again.
[klang@ergates bin]$ split_destination-test.sh
destination user@host.with.full.domain:/full/path/to/install/package.ext
server host.with.full.domain
servershort host
user user
fullpath /full/path/to/install/package.ext
path /full/path/to/install/
package package.ext
#!/bin/bash
PWD=$(pwd)
source $PWD/split_destination.sh user@host.with.full.domain:/full/path/to/install/package.ext
echo "destination $destination"
echo "server $server"
echo "servershort $servershort"
echo "user $user"
echo "fullpath $fullpath"
echo "path $path"
echo "package $package"
#!/bin/bash
# An easy way to specify a destination as a single input parameter is:
# user@host.with.full.domain:/path/to/install/package.ext
# To get the individual data elements back again, this script can be used.
destination=$1
server=${destination/#*@/}
server=${server/:*/}
servershort=${server/\.*/}
user=${destination/@*/}
fullpath=${destination/*:/}
package=${destination/*\//}
path=${fullpath/$package/}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment