LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-08-2008, 11:10 AM   #1
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
simple read $a / grep question


Hi,
I wanted to write a simple script to kill a particular program.
My question is as follows:
why does 'ps ax | grep $1' work without any problems
and 'ps ax | grep $number' returns errors with usage or grep?

Code:
#!/bin/bash

E_BADARGS=65
if [ -z "$1" ]     # Check for argument to script.
then
   echo "Usage: `basename $0` program_you_want_to_kill"
   exit $E_BADARGS
fi

echo "Type the number of the process you want to kill: "
ps ax | grep $1
echo " "
echo "No of process you want to kill: "
read $number
echo $number
ps ax | grep $number

I also tried
ps ax | grep `echo $number`
ps ax | grep $(echo $number)

thanks
 
Old 01-08-2008, 12:01 PM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
should be

read number
 
Old 01-08-2008, 12:07 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836

Original Poster
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
thanks it works fine now
 
  


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
Grep command to read a file Sherlock Programming 2 02-02-2007 04:18 AM
Simple Text Reformat (sed and grep) mikefazz Programming 2 08-31-2004 07:38 PM
Simple grep command problem acis Linux - General 2 07-16-2004 12:21 PM
Simple grep question - I hope ! MiguelE Linux - Newbie 3 04-16-2004 08:46 AM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 09:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:50 AM.

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
Open Source Consulting | Domain Registration