Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-13-2004, 09:55 PM   #1
LQ Newbie
Registered: Jul 2004
Posts: 1

Rep: Reputation: 0
A strange bash script

head -n file > ! pp

What does this line mean ? I am puzzled...
Old 07-13-2004, 10:55 PM   #2
Senior Member
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 47
Well, I can break it down a bit...

"head" prints out (usually) the first ten lines of a file. So, "head file1" would print the ten lines in the file named file1. You can modify the number of lines printed with "-n #". "head -n 22 file1" would print out the first 22 lines of the file named file1. Your script line seems to be missing the # after -n.

The ">" redirects the output of the command before it. If takes the output of the head command and sends it somewhere other than the screen. It's usually to a file. "head -n 22 file > file2" would write the first 22 lines of the file named file1 into the file named file2.

I don't know what the exclamation mark is for... It's usually used as a "not" in a conditional when you are comparing two items. "if a != b" means "if a does not equal b". Although in Bash it would be "if [a -ne b];". It prob'ly means something in the Bourne shell. The first line, "#!/bin/sh", calls the Bourne shell. If it was calling Bash, it would be "#!/bin/bash".

The pp might be another program or script that is using the print out from head, or it might be a file that the print out is going into.
Old 07-13-2004, 11:07 PM   #3
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Well it does seem a bit strange just seeing part of it. The number of lines to be displayed is missing where it should be -n 5 or some other number. The output of head is redirected to !pp and !pp is the last command in history which started with pp

So it would look like this... head -n 5 somefile > !pp


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange problem with BASH (FreeBSD 4.10) myrdd|n *BSD 9 02-18-2005 07:10 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
strange bash login error figmentium Linux - Newbie 3 08-11-2003 04:27 PM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:38 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration