From: Alex Dehnert Date: Sat, 15 Dec 2012 13:20:57 +0000 (-0500) Subject: sshroot: use set -e X-Git-Url: https://www.dehnerts.com/gitweb/?p=user%2Falex%2Fsoftware%2Fmy-snippets.git;a=commitdiff_plain;h=8b9c2d458ad86e632febcf26f71a9cb0bf5750f8 sshroot: use set -e Also, set -e doesn't cause failures when passing the output of a subshell directly to eval, so use an intermediate variable instead. --- diff --git a/sshroot b/sshroot index 845a04a..740b5ef 100755 --- a/sshroot +++ b/sshroot @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e # lifetime, in minutes lifetime=15 @@ -38,7 +38,8 @@ keychain_host="$hostopt-$keysuffix" function with-keys { unset SSH_AUTH_SOCK SSH_AGENT_PID - eval $(keychain --timeout "$lifetime" --eval --host "$keychain_host" $keys) + vars=$(keychain --timeout "$lifetime" --eval --host "$keychain_host" $keys) + eval "$vars" export SSHROOT=1 exec "$@" } @@ -46,7 +47,8 @@ function with-keys function with-agent { unset SSH_AUTH_SOCK SSH_AGENT_PID - eval $(keychain --timeout "$lifetime" --eval --host "$keychain_host") + vars=$(keychain --timeout "$lifetime" --eval --host "$keychain_host") + eval "$vars" export SSHROOT=1 echo with-agent: Running: "$@" exec "$@"