PDA

View Full Version : what is substitute for /c


himanshu
03-11-2011, 10:25 AM
$ vi ginfo
#
#
# Script to print user information who currently login , current date & time
#
clear
echo "Hello $USER"
echo "Today is %c ";date
echo "Number of user login : %c" ; who | wc -l
echo "Calendar"
cal
exit 0

this is my test script
from terminal it is not giving me /c as value
I tries %c instead of /c

SirDice
03-11-2011, 10:59 AM
Use printf.

himanshu
03-11-2011, 11:49 AM
not working

my input is :


$ vi ginfo
#
#
# Script to print user information who currently login , current date & time
#
clear
echo "Hello $USER"
printf "Today is /c";date
printf "Number of user login : /c" ; who | wc -l
echo "Calendar"
cal
exit 0


out put as

Hello Admin:

Today is /cFri Mar 11 23:19:17 IST 2011
Number of user login : /c 3
Calendar
March 2011
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 31

Admins-iMac:Documents Admin$

rccharles
03-11-2011, 12:44 PM
You need to find a better source on coding bash scripts. Bash has a very precise & unforgiving syntax.

I like:
Practical Guide to Linux Commands, Editors, and Shell Programming, A
http://www.amazon.com/Practical-Guide-Commands-Editors-Programming/dp/0131367366/ref=sr_1_1?ie=UTF8&s=books&qid=1267213314&sr=1-1
There is a newer edition:
http://www.walmart.com/ip/11314039

#!/bin/bash
# It's a good idea to include what scripting language you
# are using. Place #!/bin/bash as the first line.
#
# Script to print user information who currently login , current date & time
#
clear
echo "Hello $USER"
printf "Today is %s \n " "$(date)"
printf "Number of user login : %s \n" $(who | wc -l)
echo "Calendar"
cal
# Here is how I would have coded this.
echo
echo "Here is my coding"
echo
echo "Hello $USER"
# To find out how the echo command works use the man command.
# man echo
# You will notice the % escape are not supported.
#
# keep thing simple. Do one thing at a time.
theDate=$(date)
#
# this format of accessing bash variables will always give you
# what you are expecting: "${theDate}"
#
# ${theDate} look up the varible
# "${theDate}" the result of the variable lookup is one string.
# without the double guotes you can get many strings.
#
echo "Today is " "${theDate}"
# awk will get rid of leading blanks in the count from wc.
theCount=$(who | wc -l | awk '{print $1}')
echo "Number of user login : ${theCount}"
echo "Calendar"
cal

exit 0

himanshu
03-11-2011, 01:13 PM
Thanks Sir,

I need some good free source....I am entering IBM-AIX -> above script is related
to this, pls reply

By the way:above is very advance and sofesticated

rccharles
03-12-2011, 11:42 AM
Thanks Sir,

I am entering IBM-AIX -> above script is related to this

Are you copying AIX scripts? You should include what scripting language in the first line like I did.

for Bash syntax see Advanced Bash Script. I have revision 6.2.
tldp.org/LDP/abs/abs-guide.pdf

BASH Programming - Introduction HOW-TO
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html#toc14

Sometimes you can get a good deal on used book in Amazon.
http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=0131367366&x=0&y=0

I found the second addition of this at my local library. Any book on Bash syntax will do. There will be minor differences but they will not be great.

Robert

himanshu
03-14-2011, 07:57 AM
not coping any scripts. learning from Linux blogs
how to do scripting....I will go further in AIX after learning
that what I want to say...

I want to know .sh,.ksh and .bash scripting

SirDice
03-14-2011, 08:59 AM
I want to know .sh,.ksh and .bash scripting
Ok, start with the proper naming. sh is the classic Bourne Shell. ksh is called the Korn Shell and bash is the Bourne Again SHell. They have quite some similarities but also some major differences.

http://www.grymoire.com/Unix/Sh.html