Skip to content

Commit 88a51b4

Browse files
committed
ktest.pl: Add shell commands to variables
Allow variables to execute shell commands. Note, these are processed when they are first seen while parsing the config file. This is useful if you have the same config file used for multiple hosts (as they may be in a git repository). HOSTNAME := ${shell hostname} DEFAULTS IF "${HOSTNAME}" == "frodo" Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 26df05a commit 88a51b4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

tools/testing/ktest/ktest.pl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,14 @@ sub process_variables {
802802
my $end = $3;
803803
# append beginning of value to retval
804804
$retval = "$retval$begin";
805-
if (defined($variable{$var})) {
805+
if ($var =~ s/^shell\s+//) {
806+
$retval = `$var`;
807+
if ($?) {
808+
doprint "WARNING: $var returned an error\n";
809+
} else {
810+
chomp $retval;
811+
}
812+
} elsif (defined($variable{$var})) {
806813
$retval = "$retval$variable{$var}";
807814
} elsif (defined($remove_undef) && $remove_undef) {
808815
# for if statements, any variable that is not defined,

tools/testing/ktest/sample.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@
259259
# If PATH is not a config variable, then the ${PATH} in
260260
# the MAKE_CMD option will be evaluated by the shell when
261261
# the MAKE_CMD option is passed into shell processing.
262+
#
263+
# Shell commands can also be inserted with the ${shell <command>}
264+
# expression. Note, this is case sensitive, thus ${SHELL <command>}
265+
# will not work.
266+
#
267+
# HOSTNAME := ${shell hostname}
268+
# DEFAULTS IF "${HOSTNAME}" == "frodo"
269+
#
262270

263271
#### Using options in other options ####
264272
#

0 commit comments

Comments
 (0)