A quick query


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A quick query
# 1  
Old 02-29-2012
Tools A quick query

Hello All,

i am facing an issue and could not understand the possible reason...

When the following command is executed from command line (from # prompt) the output is as desired but executing the same from a shell script, the result is an error. It is important for the command to execute in the script as there are other calculations dependent on this variable.

Quote:
s=(`ls -lrth /2702/ | awk '{print $9;}' | sed s/iostat.// | cut -c5-6`)
command executed from command line and output is an array with values as desired
Quote:
bash-3.00# echo ${#s[@]}
144 ---> total no. of vaules from above command
bash-3.00# echo ${s[141]}
01 ----> one of the array values
bash-3.00#
executing same from script
Quote:
bash-3.00# sh iodata_extr
iodata_extr: syntax error at line 6: `s=' unexpected
Excerpt of the script is something like this
Quote:
#!/bin/bash
cd /
j=3;
k=p;
a=1;
s=(`ls -lrth /2702/ | awk '{print $9;}' | sed s/iostat.// | cut -c5-6`)
I appreciate if the issue can be resolved as soon as possible.
# 2  
Old 02-29-2012
Strange.. It works for me.

Code:
#! /bin/bash
x=(`ls test*`)
echo ${x[1]}
echo ${x[@]}

Code:
$ ./test.sh
test.pl
test.cgi test.pl test.sh


Last edited by balajesuri; 02-29-2012 at 08:25 AM.. Reason: Corrected post. Didn't read the question properly the first time.
# 3  
Old 02-29-2012
@balajesuri. Thank you for your reply. I believe removing round paranthesis doesn't make it an array. Please correct my understanding.

Secondly, /2702/ is just a directory with files.
# 4  
Old 02-29-2012
Use bash iodata_extr or ./iodata_extr instead of sh iodata_extr
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 5  
Old 02-29-2012
Bourne shell "sh" does not support this...
Code:
s=(`ls -lrth /2702/ | awk '{print $9;}' | sed s/iostat.// | cut -c5-6`)

use bash...

Last edited by Franklin52; 02-29-2012 at 08:58 AM.. Reason: Please use code tags for code and data samples, thank you
This User Gave Thanks to Vidhyaprakash For This Post:
# 6  
Old 03-04-2012
it worked with bash...Thank you all for valuable time and support.
# 7  
Old 03-04-2012
HI EMBEDUX

IM WORKING IN DATA WAREHOUSING PROJECTS
PRESENT WHICH TECHNOLOGY BETTER FOR UNIX...

AND PLEASE TELL ME WHICH UNIX BOOK SUITABLE FOR UNIX ADMINISTRATION

THANKS!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File grep quick query

Hi Experts, I need some suggestion on file grep. I am trying to find multiple pattern with the file grep as below grep "2013" trace.log | grep -f pattern.cfg -i > $LOG if ; then mail -s "Exception" "sample@abc.com" < $LOG fi Is it possible to obtain what pattern I got in the... (5 Replies)
Discussion started by: senthil.ak
5 Replies

2. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

3. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

4. Shell Programming and Scripting

add the output of a query to a variable to be used in another query

I would like to use the result of a query in another query. How do I redirect/add the output to another variable? $result = odbc_exec($connect, $query); while ($row = odbc_fetch_array($result)) { echo $row,"\n"; } odbc_close($connect); ?> This will output hostnames: host1... (0 Replies)
Discussion started by: hazno
0 Replies

5. Solaris

Quick help!

Hi, iam trying to use lofiadm in solaris 5.10 but getting the following error.. bash-3.00# lofiadm -a /asmdisks/_file_disk1 lofiadm: /dev/lofictl: No such file or directory i dont see lofictl file in /dev .. i checked in other similar machines..i found this file..can i export this file from... (2 Replies)
Discussion started by: rags_s11
2 Replies

6. Shell Programming and Scripting

Quick one

Hallo friends, I have a log file called xxx.log which is generated everymorning. I want to change this file to xxx_.log Please assist, i am using ksh on AIX. Ta, Pax (4 Replies)
Discussion started by: kekanap
4 Replies

7. Shell Programming and Scripting

Need quick help

I have one script that named testing.sh #cat testing.sh #/bin/bash echo "Enter your name:" read name #./testing.sh Enter your name: Sanjay What I need it should take Input in the same prompt(mean to say dun go for next line) like given below. #./testing.sh Enter your name:Sanjay ... (1 Reply)
Discussion started by: SanjayLinux
1 Replies

8. UNIX for Dummies Questions & Answers

i need quick help???...please

hey guys i'm new in this world " unix " i wanna any websites can help me to learn unix or any websites i can download UNIX from it thanks :D (3 Replies)
Discussion started by: M_Hafez
3 Replies

9. UNIX for Dummies Questions & Answers

Quick Question

I know in DOS, when you want to pull up your last/previous command, you hit the up/down arrows. How do you do that with UNIX? (3 Replies)
Discussion started by: Tracy Hunt
3 Replies
Login or Register to Ask a Question