Thursday, November 8, 2012

Shell scripting: conditional string concatenation

Run a different command depending on an input parameter. Make use of an if statement, concatenate 2 strings and run the resulting bash command.

#!/bin/bash

if [[ "$1" == "pro" ]]; then

part1="ls -la"
else
part1="ls"
fi


part2="/home/dir";

command=$part1$part2;

eval $command


No comments: