I'm trying to print calendar using shell script and i'm able to print it. But the format is not good.
Here is the script.
#!/bin/bash
echo $(date)
echo "Hello $USER"
echo Hostname $(hostname)
echo Working in $(pwd)
echo Here is this month calender
echo $(cal)
[cracha@cs ~]$ sh first.sh
Mon Sep 22 12:37:42 IST 2014
Hello cracha
Hostname cs
Working in /home/cracha
Here is this month calender
September 2014 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
[cracha@cs ~]$
Please let me know how to print it in right format.
$(..) is the syntax that replaced ` command something ` the result is the execution of the code between the braces..
For the quotes and double quotes its best you experience with them and you tell us what you understood: e.g.
If you don't know what $(cal) does, why did you use it in your script?
If you use echo $(cal) with command substitution and no quotes, all of the sequences of whitespace characters will be converted by the shell into single spaces before being passed to echo . The text between single quotes will be treated by the shell unchanged as a single operand. The text between double quotes will be treated by the shell as a single operand after performing variable expansions, arithmetic expansions, and command substitutions. Compare the results from the following commands: