Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Sunday, February 24, 2013

shell script echo new line to file


var1="Hello"
var2="World!"
logwrite="$var1\n$var2"
echo -e "$logwrite"  >> /Users/username/Desktop/user.txt
Explanation:
The \n escape sequence indicates a line feed. Passing the -e argument to echo enables interpretation of escape sequences.
It may even be simplified further:
var1="Hello"
var2="World!"
echo -e "$var1\n$var2"  >> /Users/username/Desktop/user.txt
or even:
echo -e "Hello\nWorld! "  >> /Users/username/Desktop/user.txt

How to tell if a string is not defined in a bash shell script

#!/bin/bash

if [ -z $1 ]; then
        echo 'Enter something please.';
        exit 1;
fi;