Click to See Complete Forum and Search --> : Anybody know a good online tutor for bash/sh ???


chris65
06-28-2002, 01:17 AM
I need help learning bash/sh and writing shell files.
Does anybody know a good online tutor or free class that I might get
some usefull info from? I am out of work at the time and cant afford a book
right now. (that will change soon) but i need a free page or something to help
me learn for now. I also need help with this...

#!/bin/bash
echo "You are in:"
pwd
$#ls | wc -w
echo "There are $# files in the current dir."

It prints the pwd part, but the string returns a zero number.
how do i get it to return the value of the number of files in the cd.
Thanks in advance

fancypiper
06-28-2002, 01:53 AM
The Gentoo site has an article by one of the developers of the sistro that looks interesting. It's Bash by example (http://www-106.ibm.com/developerworks/library/bash.html) on an IBM site that requires registration and of course, there are a couple of bash howtos at the LDP.

truls
06-28-2002, 02:40 AM
No of files:

set noFiles = `ls -la | wc-l`
echo "number of files is $noFiles"

Should do it. Note that ` is not '.

T.

ps: This is a really silly question, but what are the english words for the ` ' ^ @ characters?

Hena
06-28-2002, 02:56 AM
Best guide that i've found for bash is Advanced Bash-Scripting Guide (http://www.tldp.org/LDP/abs/html/).

These are in "i think" category of my ability :):
@ = at sign
^ = caret
' = single quote
` = backtick

[ 28 June 2002: Message edited by: Hena ]

chris65
06-28-2002, 03:34 AM
Thanks, the sites you all recomended look good. I bookmarked them
and will use them well. Got the code fixed also.thanks truls.
this site, Advanced Bash-Scripting Guide.has a download so i can use it
offline.thanks hena.
got one moor if you are up to it.

If i were to use this script how would i need to conf the password
and user name files. do i put them in te etc/passwords file??
do i need to make a "echo what is your username" statement and have it
return a value?

# make sure at least one parameter is passed in
if [ "$1" = "" ]
then
echo ERROR: expect one paremeter representing a username
exit 1
fi

# make sure the username is a valid one for the system
grep -s $1: /etc/passwd

if [ $? -ne 0 ]
then
echo The username $1 is not valid for this system.
exit 1
fi

# see if user is logged in
w | cut -d' ' -f1 | grep -s $1

if [ $? -eq 0 ]
then
echo $1 is currently using the system
exit 0
else
echo $1 is not using the system
exit 1