sm-sorcery-bugs AT lists.ibiblio.org
Subject: Bugs for Sorcery are reported here
List archive
[SM-Sorcery-Bugs] [Bug 10441] New: new function that might be useful
- From: bugzilla-daemon AT bugs.sourcemage.org
- To: sm-sorcery-bugs AT lists.ibiblio.org
- Subject: [SM-Sorcery-Bugs] [Bug 10441] New: new function that might be useful
- Date: 22 Jan 2006 21:32:43 -0000
http://bugs.sourcemage.org/show_bug.cgi?id=10441
Summary: new function that might be useful
Product: Sorcery
Version: Untargetted future release
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Unknown
AssignedTo: sm-sorcery-bugs AT lists.ibiblio.org
ReportedBy: juuso.alasuutari AT tamperelainen.org
I wrote a function that I believe might be useful for various scripting
purposes.
It takes a string and any number of variable names, and replaces all
instances
where the expanded variables occur in the string with their respective
variable names.
Yeah, I thought that wasn't clear enough...
If:
URL=http://www.site.org/program/0.99/program-0.99.tar.gz
SERVER=http://www.site.org
NAME=program
VERSION=0.99
OUTPUT=$(substitute_with_variable_names $URL SERVER NAME VERSION)
# notice that the variable names after the first one don't have $
Then:
'echo $OUTPUT' will produce "$SERVER/$NAME/$VERSION/$NAME-$VERSION.tar.gz"
More specific wrapper functions can be written that make use of this one.
Please tell me what you think, and if you think there is reason to include
this as a "global" sorcery function. (Excuse me if I don't appear to know
what
I'm talking about, because I don't. ;))
wu-hsin
PS: The function has a long and ugly name, change it if you wish.
Here's the code:
function substitute_with_variable_names() {
if [ -n "$1" ]; then
local TARGET_STRING="$1"
shift 1
else
return 1
fi
if [ -n "$1" ]; then
while [ -n "$1" ]; do
TARGET_STRING=${TARGET_STRING//${!1}/\$$1}
shift 1
done
fi
echo $TARGET_STRING
}
--
Configure bugmail: http://bugs.sourcemage.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
- [SM-Sorcery-Bugs] [Bug 10441] New: new function that might be useful, bugzilla-daemon, 01/22/2006
Archive powered by MHonArc 2.6.24.