sh-utils.sh revision fc9431d0d0cb8e19c7df04e077efdbe3ac173431
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# $Id$
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Shell script include file
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay## @file
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Shell script routines which are likely to be useful for different scripts
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay#
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay#
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Copyright (C) 2009-2011 Oracle Corporation
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay#
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# This file is part of VirtualBox Open Source Edition (OSE), as
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# available from http://www.virtualbox.org. This file is free software;
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# you can redistribute it and/or modify it under the terms of the GNU
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# General Public License (GPL) as published by the Free Software
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Foundation, in version 2 as it comes in the "COPYING" file of the
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay#
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Deal with differing "which" semantics
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemaymywhich() {
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay which "$1" 2>/dev/null | grep -v "no $1"
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay}
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Get the name and execute switch for a useful terminal emulator
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay#
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Sets $gxtpath to the emulator path or empty
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Sets $gxttitle to the "title" switch for that emulator
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Sets $gxtexec to the "execute" switch for that emulator
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# May clobber $gtx*
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Calls mywhich
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemaygetxterm() {
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay # gnome-terminal uses -e differently to other emulators
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay for gxti in "gnome-terminal --title -x" "konsole --title -e" "xterm -T -e"; do
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay set $gxti
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay gxtpath="`mywhich $1`"
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay case "$gxtpath" in ?*)
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay gxttitle=$2
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay gxtexec=$3
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay return
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay ;;
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay esac
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay done
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay}
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# Quotes its argument by inserting '\' in front of every character save
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay# for 'A-Za-z0-9/'. Prints the result to stdout.
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemayquotify() {
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay echo "$1" | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g'
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay}
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay