A good start but there's a few things to figure out here:
You don't put programs inside [ ] like that, you can just put them there raw.
That is also a useless use of cat, whenever you have cat stuff | program it's better to do program < stuff.
There's a trick you can do with grep to check for a user in the password file:
The ^ makes it look at the beginning of the line, so it looks for ${username}: at the beginning of any line in /etc/passwd. The -q tells it not to print anything, just return true or false as usual.
This is a useless use of backticks (since the $(stuff) syntax is a special form of backticks). You don't check a return value in that fashion, either -- what that statement would actually end up doing is checking the string output of who | grep $username.
How you check a return value is like:
So how about:
1 means error, by returning 1 you're telling whatever ran it that your program failed. Use 'exit 0' to show that your program ran successfully.
Validate your input not blank, is in /etc/passwd, first, before proceeding, if bad then display, exit -- done, no deep nesting, all parts of the function point close together. A cat is not necessary to get files to stdin, < does that cheaper. One user name might be a substring of another, so the grep of who should be more qualified. date can produce the entire message using a "+%Y-%m-%d %H:%M:%S $username" sort of argument, and have a nicer format. $(xxx) is not for diplaying variables, that is ${xxx}, $(xxx) turns a command or script stdout into a string on the command line, just the opposite of echo, which turns a string on the command line into a stream on stdout. The error message does not describe the error, unnown user name.
Hey all,
I would like to ask your help and sorry in advance for my ignorance since I am a complete beginner in this.
I need to create a UNIX script that will:
- scan a small number of folders and subfolders (see a similar file tree in the attachment)
-
- for each final folder (each of... (8 Replies)
Given the following code inside the function ext3_write_super():
(It's there in Linux kernel 2.6.27.59)
static void ext3_write_super (struct super_block * sb)
{
if (mutex_trylock(&sb->s_lock) != 0)
BUG();
sb->s_dirt = 0;
}
The conditional test at if... (2 Replies)
i am new to shell scripting!! i am making this program in bourne shell, that asks the user to input "Hello (their name)" or "question (their name)", any other input, "ERROR" will be outputted.
if they input "Hello (name)", i want to out saying Hello (name) but if they input "question (name)", i... (4 Replies)
List directories at the home directory in increasing order.
First of all is this correct?
cd ~/
du -h|sort -n|more
First command is to go to the home directory and second does the rest.
Is there a way to do them in single command.
Thanks in advance. (1 Reply)
Basically, I'm trying to install this program called MAQ.
Maq User's Manual
I've downloaded it and I tried to type in $ ./configure; make; make install
but the ouput I got was this:
bash: ./configure: No such file or directory
make: Entering directory `/home/vlay/bwa-0.5.0'
make:... (8 Replies)
The circumfrence of a circle is
#!/usr/bin/perl
print 2 * 3.141592654 * 12.50 \n"; # pi= 3.141592654
# r= 12.50
I need a simple program showing me all the steps..to modify the above to prompt for and accept a radius from the person running the... (3 Replies)
I don't know if it is right to ask you this. Can someone help me write a simple Xlib program,with button on it,and all that button do is switch 2 messages.
I have tried and tried,but never get past Hello World. Can someone help me please?
---------- Post updated at 10:17 PM ---------- Previous... (2 Replies)
I am new to the unix/linux environment.
AND........
I need to create a mini shell..that displays prompt (i.e., READY:$), accepts a command from std-in, and prints the command and any parameters passed to it. HELP!!!! (8 Replies)