summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2005-08-24 21:51:10 +0000
committerrillig <rillig@pkgsrc.org>2005-08-24 21:51:10 +0000
commit66a0b139ae51e0c4682eb663f1bddb234a1898fc (patch)
tree6181aaa2be6219a9a89f4ff090801fe36b47518f /mk
parentc143c1d23648ac4d3e56b6d53246c79a5a506771 (diff)
downloadpkgsrc-66a0b139ae51e0c4682eb663f1bddb234a1898fc.tar.gz
Added a code snippet that demonstrates how to set the $@ array to the
lines printed by a shell command. In contrast to the read(1) shell utility, there are no problems when the output contains backslashes.
Diffstat (limited to 'mk')
-rw-r--r--mk/scripts/shell-lib13
1 files changed, 12 insertions, 1 deletions
diff --git a/mk/scripts/shell-lib b/mk/scripts/shell-lib
index 1d8cb95ac40..23a45cd4876 100644
--- a/mk/scripts/shell-lib
+++ b/mk/scripts/shell-lib
@@ -1,4 +1,4 @@
-# $NetBSD: shell-lib,v 1.2 2004/09/21 15:14:08 jlam Exp $
+# $NetBSD: shell-lib,v 1.3 2005/08/24 21:51:10 rillig Exp $
#
# Copyright (c) 2004 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -383,3 +383,14 @@ fqueue_is_empty()
return 1
fi
}
+
+######################################################################
+# $setargs_from_cmd
+# Run $cmd and initialize the $@ array with the lines from that
+# command.
+# usage:
+# cmd="echo *"; eval "${setargs_from_cmd}"
+# for i in "$@"; do echo "($i)"; done
+######################################################################
+setargs_from_cmd='saved_IFS="${IFS}"; IFS="
+"; set args `eval "${cmd}"`; IFS="${saved_IFS}"; shift'