LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-16-2003, 04:20 AM   #16
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30

yes, that is correct, the 1 isn't part of the argument list.

Code:
1> /dev/null
This redirects all output to channel 1 (standard output) to /dev/null, which is some sort of black hole device. It trashes the grep ouput, so you don't see it at the console. You may omit the "1", because it's the default.
Code:
if tty | grep "pts" 1> /dev/null; then
In this case, I pass the ouput of "tty" to "grep", ouput is trashed to /dev/null. If the "grep" exits with an exit-code indicating 'success'; ie. the pattern was found, "if" will continue with the first block.
Code:
if [ "`tty | cut -c 0-3`" -eq "tty" ]; then

# it can be re-written as:
if test "`tty | cut -c 0-3`" -eq "tty" ; then
...notice the [square blacklets] here. I forgot them
This statement is even more complex. The backticks (` ... `) are used to execute one command inside another. The result will be inserted in the orginal command line.

If you want to understand how backtick trick works, try these commands:
Code:
date
echo "Hello"
echo "Hello, it's `date` now!"
hope this helps

it's quite little technical imho, but I hope you can understand it
 
Old 10-16-2003, 04:21 AM   #17
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
So your new code should be:
Code:
# Check if the word pts is found in the output of "tty":
if tty | grep "pts" 1> /dev/null; then
  echo 11
else
  echo 00
fi

# Check if the first 3 characters match "tty"
if [ "`tty | cut -c 0-3`" -eq "tty" ]; then
  echo 11
else
  echo 00
fi
this time with the square blacklets
 
Old 10-28-2003, 11:27 PM   #18
SpecialK5106
LQ Newbie
 
Registered: Oct 2003
Location: Gainesville, FL
Distribution: Slackware 9.1
Posts: 17

Original Poster
Rep: Reputation: 0
Sorry for not responding sooner, but I've been insanely busy. Thanks for the backtick trick, yapp! That's definitely something I'll be using now.
 
Old 10-29-2003, 08:46 AM   #19
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
hi.

that doesn't matter but thank you for dropping by.
 
  


Reply


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
How to check in a script whether the shell is login or non login? frankie_DJ Programming 7 10-21-2015 11:09 AM
localhost login erick66 Linux - Newbie 7 11-08-2005 08:50 PM
localhost login???? terry.trent Linux - Newbie 3 10-18-2003 08:02 PM
localhost login, how?? magis Linux - Newbie 4 11-24-2001 06:05 AM
Localhost Login Roy Linux - General 3 05-14-2001 05:49 PM


All times are GMT -5. The time now is 03:15 PM.

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