Understanding ampersand (&) usage in the command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Understanding ampersand (&) usage in the command
# 1  
Old 05-18-2010
Understanding ampersand (&) usage in the command

Please explain the usage of ampersand in the following command
Code:
who & echo "Total number of users are `who|wc -l`"

What I understand is that ampersand is used to run some process in the background. And, what I am expecting from this command is

"Output of who should be displayed on the screen with value of total number of users who have logged in displayed at the bottom of the list."

Thanks.
# 2  
Old 05-18-2010
You are right but I guess that this is just a typo and missing a 2nd adjacent & like marked bold here:
Code:
who && echo "Total number of users are `who|wc -l`"

This works then like if the 1st who is successful, the command following will be executed, maybe to check if "who" itself is available and working. Sending "who" in the background and then following up the rest of commands would make no sense.
# 3  
Old 05-18-2010
Thanks a lot. It does help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Nohup with ampersand & process gets disconnected

For years I have spawned shell scripts with nohup and ampersand and they run whether or not I stay logged in. Recently a client told us that we had to set a keep alive timeout on all of our Redhat 7.6 Linux servers. Our sysadmin set the following parameters in the sshd_config file on all of our... (10 Replies)
Discussion started by: gandolf989
10 Replies

2. Shell Programming and Scripting

Problems with ampersand (&) in sed command

Hello everybody, I have a Problem with sed command. I want to replace a defined string with a string from a database field (dynamic). e.g. sed -i -e 's/%NAME%/'"$HNAME"'/g' The Problem is that the $HNAME variable can contain Special characters like '&' e.g. HNAME="AH Kruger & Co. KG" ... (1 Reply)
Discussion started by: Bambuti2000
1 Replies

3. Solaris

Understanding & Monitoring CPU performance (Load vs SAR)

Hi all, Been reading a lot of the cpu load and its "analogy of it to car traffic path of expressway" From wiki Most UNIX systems count only processes in the running (on CPU) or runnable (waiting for CPU) states. However, Linux also includes processes in uninterruptible sleep states... (13 Replies)
Discussion started by: javanoob
13 Replies

4. Shell Programming and Scripting

help understanding regex with grep & sed

I have the following line of code that works wonders. I just don't completely understand it as I am just starting to learn regex. Can you help me understand exactly what is happening here? find . -type f | grep -v '^\.$' | sed 's!\.\/!!' (4 Replies)
Discussion started by: trogdortheburni
4 Replies

5. UNIX for Dummies Questions & Answers

Ampersand usage and Emacs

In the terminal, using the ampersand allows the process to run in the background--Emacs, for example. But is there a way to automatically open Emacs as a background process so I can still use the command line? Typing the ampersand is just annoying to me, and I keep forgetting; it's just too useful... (0 Replies)
Discussion started by: Zucriy Amsuna
0 Replies

6. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

7. UNIX for Dummies Questions & Answers

usage of 2>&1 while appending

Hi, 17 11 * * * /xx/yy/name.sh >> /tmp/cron.log 2>&1 The above statement is one of the crontab entries. The crong log is getting appended everytime. Can anyone tell me the usage of "2>&1"? Thanks. (2 Replies)
Discussion started by: venkatesht
2 Replies

8. UNIX for Advanced & Expert Users

How to find out memory & cpu usage of a process

Hi, By using time command we can determine the execution time of a process or command. bash-2.04$ time ls -l total 0 -rw-r--r-- 1 admin tac 0 Oct 6 04:46 file1 -rw-r--r-- 1 admin tac 0 Oct 6 04:46 file2 real 0m0.002s user 0m0.000s sys 0m0.001s... (5 Replies)
Discussion started by: learn more
5 Replies

9. UNIX for Dummies Questions & Answers

Understanding 2>&1

Hi, I have this line in a script: if mt -f /dev/nst0 rewind > /tmp/status_nst0.log 2>&1 ; then What does the 2>&1 mean? I think the line is saying that after rewinding the device if the log file does not exist then execute the code but I do not understand the contribution of the 2>&1.... (2 Replies)
Discussion started by: mojoman
2 Replies

10. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies
Login or Register to Ask a Question