Simple ksh script problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple ksh script problem
# 8  
Old 09-09-2005
Could please tell were to specifically put the could you gave. I have no idea where to put the code.

Code:
compfile=~/sample_data.txt
clear
bold=`tput smso`
offbold=`tput rmso`
echo $bold
tput cup 3 1; echo "UsedComputersRUs Menu- Search Computer"
echo $offbold
tput cup 4 1; echo "======================================"
tput cup 5 1
echo "Enter computer to search for: "
tput cup 5 31
read compdate
echo
grep -i $compnumber $compdate $model $manufacturer $price $compfile
if [ $? -eq 1 ]
then
echo "No Matching Records Found"
fi
echo 
echo "Press ENTER to continue..."
read continue


Last edited by Warrior232; 09-09-2005 at 11:40 PM..
# 9  
Old 09-10-2005
It was pretty clear from vgersh99's post where to place his solution.

Anyway, here it is.

Code:
#! /bin/ksh
compfile=~/sample_data.txt
.
.
read compdate
echo

exec 3>&1
eval $(exec 4>&1 >&3 3>&-
  {
   grep -i $compnumber $compdate $model $manufacturer $price $compfile 2>&1 4&-; echo "exitCode=$?"; >&4
   } | tr ':' ' '
);

if [ ${exitCode} -eq 1 ]
then
echo "No Matching Records Found"
fi
echo "Press ENTER to continue..."

read continue


Last edited by vino; 09-10-2005 at 07:22 AM..
# 10  
Old 09-10-2005
I get same error. That is way asked where to place the new code. I was testing it before an I keep on getting the same error. I don't understand what the error message states.

Last edited by Warrior232; 09-10-2005 at 01:16 PM..
# 11  
Old 09-10-2005
Try this..

Code:
#! /bin/ksh
compfile=~/sample_data.txt
.
.
read compdate
echo

exec 3>&1
eval $(exec 4>&1 >&3 3>&-
  {
   grep -i $compnumber $compdate $model $manufacturer $price $compfile 2>&1 4&-; echo "exitCode=$?"; >&4
   } | tr ':' ' '
);

if [[ ${exitCode} -eq 1 ]]
then
echo "No Matching Records Found"
fi
echo "Press ENTER to continue..."

read continue

# 12  
Old 09-10-2005
Same error message

UsedComputersRUs Menu- Search Computer
======================================
Enter computer to search for: sony

grep can't open 4
/studes/LAC220/g1ae020/sample_data.txt 016 18-12-2005 Sony Centrino-1.6Ghz 2000.00
/studes/LAC220/g1ae020/sample_data.txt 017 18-01-2006 Sony Centrino-1.6Ghz 5000.00
/studes/LAC220/g1ae020/sample_data.txt 020 22-02-2006 Sony Centrino-1.6Ghz 2000.00
/studes/LAC220/g1ae020/sample_data.txt 022 03-04-2005 Sony Centrino- 1.6Ghz 3500.00
/studes/LAC220/g1ae020/sample_data.txt 023 26-06-2006 Sony Centrino- 1.6Ghz 2345.00
./search.txt[26]: -: not found
exitCode=127
Press ENTER to continue...
# 13  
Old 09-10-2005
fix this line ...

Code:
grep -i $compnumber $compdate $model $manufacturer $price $compfile 2>&1 4>&-; echo "exitCode=$?"; >&4

# 14  
Old 09-10-2005
This is the output the I get from below code. However I still dont get the "No Matching Records Found" when a record does not exist.

UsedComputersRUs Menu- Search Computer
======================================
Enter computer to search for: sony

016 18-12-2005 Sony Centrino-1.6Ghz 2000.00
017 18-01-2006 Sony Centrino-1.6Ghz 5000.00
020 22-02-2006 Sony Centrino-1.6Ghz 2000.00
022 03-04-2005 Sony Centrino- 1.6Ghz 3500.00
023 26-06-2006 Sony Centrino- 1.6Ghz 2345.00
exitCode=0
Press ENTER to continue...



Code:
#! /bin/ksh
compfile=~/sample_data.txt
clear
bold=`tput smso`
offbold=`tput rmso`
echo $bold
tput cup 3 1; echo "UsedComputersRUs Menu- Search Computer"
echo $offbold
tput cup 4 1; echo "======================================"
tput cup 5 1
echo "Enter computer to search for: "
tput cup 5 31
read compdate
echo
exec 3>&1
eval $(exec 4>&1 >&3 3>&-
  {
   grep -i $compnumber $compdate $model $manufacturer $price $compfile 2>&1 4>&-; echo "exitCode=$?"; >&4
   } | tr ':' ' '
);

if [[ ${exitCode} -eq 1 ]]
then
echo "No Matching Records Found"
fi
echo "Press ENTER to continue..."
read continue

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script (simple problem)

I want to find and replace string from files present in one directory. user will input the string to be searched and to replace . Here is my program but Not working echo "Enter Old domain name:" read old echo "Enter New domain name:" read new grep -rl '$old' /var/www/ | xargs sed -i... (4 Replies)
Discussion started by: sunny2802
4 Replies

2. Shell Programming and Scripting

how to execute ksh simple shell script without creating .sh file

please help me to execute a simple shell script like for i in `ls echo $i done . i dont want to create a new sh file to execute it. Can i just type and execute it ? because I always this kind of simple for loops . Please help . Thanks (7 Replies)
Discussion started by: Sooraj_Linux
7 Replies

3. Shell Programming and Scripting

[newb] simple script, big problem

Warning! I'm ridiculously new at all this, so pardon my ignorance... I have a very simple script which is intended to search a hosts file when given a partial hostanme or ip address. The if the partial hostname/ip given is unique, the script automatically logs the user in to that host. If... (6 Replies)
Discussion started by: itomb
6 Replies

4. Shell Programming and Scripting

Simple bash script problem

#!/bin/bash cd /media/disk-2 Running ./run.sh it's not changing directory.Why? (6 Replies)
Discussion started by: cola
6 Replies

5. UNIX for Dummies Questions & Answers

simple script with while loop getting problem

Hello forum memebers. can you correct the simple while program. #! /bin/ksh count=10 while do echo $count count='expr$count-1' done I think it will print 10 to 1 numbers but it running for indefinite times. (2 Replies)
Discussion started by: rajkumar_g
2 Replies

6. Shell Programming and Scripting

Simple AWK script problem.

Hi all, I have set up a simple awk script to calculate the average of values that are printed out a number of times per second (the number of time the printing occurs varies). The data is of the format shown below: 1 4.43 1 3.65 1 2.45 2 7.65 2 8.23 2 5.65 3 4.65 3 6.21 .. .. 120... (4 Replies)
Discussion started by: omnomtac
4 Replies

7. Shell Programming and Scripting

one simple shell script problem

Hi everyone, I am facing to one shell script problem, which is as following Write a shell script that: Takes a number of arguments. For each argument, print out all files in the current directory that contain this substring in their name. I know I need to use grep for the second... (7 Replies)
Discussion started by: shaloovia
7 Replies

8. Shell Programming and Scripting

Simple script problem

Hi everyone - I am sure this is a really simple problem but I'm a total noob at Linux scripting: I wanted to create a script that allows me to compare the current week number to the contents of a text file in my home directory: VAR1='date +%V' VAR2='cat /home/fred/file.txt' ... (6 Replies)
Discussion started by: FiniteRed
6 Replies

9. Shell Programming and Scripting

need help with simple awk/ksh script

I need help finding out why this script wont run. The chmod is okay, but i get an error saying that I need '&&' on line 5. (18 Replies)
Discussion started by: tefflox
18 Replies

10. UNIX for Dummies Questions & Answers

simple shell script problem

hi all. i have a little problem. im basically reading input from the user from the keyboard into the variable "phonenumber". I want to do a little error check to check if the user doesnt enter anything in for the value phonenumber. i had this: read phonenumber if then ..... else ........ (2 Replies)
Discussion started by: djt0506
2 Replies
Login or Register to Ask a Question