Sponsored Content
Top Forums Shell Programming and Scripting My script is not giving result for 2 or more arguments Post 302365416 by baigmd on Tuesday 27th of October 2009 02:30:38 AM
Old 10-27-2009
Doesn't work

---------- Post updated at 02:30 AM ---------- Previous update was at 02:17 AM ----------

I got the solution ....thanks...sharing with you guys
Code:
#!/bin/sh
sname=$(basename $(readlink -nf $0))
echo "This is $sname, running at $(date)"
echo "It is running on $(hostname)"
echo "Script being run by"
echo " User $(grep "^$USER:" /etc/passwd | cut -d: -f1)"
echo " UID $(grep "^$USER:" /etc/passwd | cut -d: -f3)"
echo " who is really $(grep "^$USER:" /etc/passwd | cut -d: -f5)"
echo ""
echo "Called with $# arguments"
array=("$@")
for ((i=0 ; i < $# ; i++))
do
if test -f "${array[$i]}"
then  
echo "-> Argument ${array[$i]} is a file"
ls -l ${array[$i]}
else
  echo "-> Argument ${array[$i]} either is not a regular file, or doesn't exist"
fi
done


Last edited by pludi; 10-27-2009 at 04:11 AM.. Reason: code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Giving input through script

Script 1.ksh ========= /home/adw/a.ksh << ** a b Script 1.ksh is working fine even without ending "**" Script 2.ksh ========= if then /home/adw/a.ksh << ** a b fi But the script 2.ksh is giving error "syntax error : `<<' unmatched". Is it bcoz of fi. (1 Reply)
Discussion started by: radhika03
1 Replies

2. UNIX for Dummies Questions & Answers

Script giving different result on Linux compared to Unix

Hi I have a script executing fine in Unix but in linux I am getting different result. I have three files under /local/home/temp/Gen test.sh list.txt shst.txt Contents of test.sh -------------------------- #!/bin/ksh K=0; SCRIPT_DIR=/local/home/temp/Gen cat... (2 Replies)
Discussion started by: malavm
2 Replies

3. Programming

Test program not giving expected result

I have five classes. 2 composition classes,1 aggregation class and 1 dependency class.I have coded all the classes but one of my test program is not giving me the expected result.I have the following classes: TimeStamp Interval (composition of 2 TimeStamps) TimeSheet ( aggregation of many... (3 Replies)
Discussion started by: moraks007
3 Replies

4. Shell Programming and Scripting

$0 not giving script name

Why does $0 return the word usage rather than the script name when used in a function? Baffeled on this one, any help appreciated. usage() { echo "$0 -cs <number of batches>\n" echo "$0 -c 4" echo "$0 -s 4" # echo "-c = Create" # echo "-s = Submit\n" exit 1 } $... (1 Reply)
Discussion started by: nhatch
1 Replies

5. AIX

errpt not giving a result

my system get rebooted by its self after its came up i try to check the error log P690/>errpt | more Cannot open error message catalog /usr/lib/nls/msg/en_US/codepoint.cat. The error report will still run, but it will not have explanatory messages P690/>ls -lrt... (1 Reply)
Discussion started by: thecobra151
1 Replies

6. Shell Programming and Scripting

Monitoring Sript giving random end result

Hi Guys, I am developing a script to monitor GUI based FileNet Component "Component Manager" which logs it's running status in a log file. Log file is a huge file so in script I put last 300 lines of log file in seperate file and run script every 5 minutes. I am searching the string... (2 Replies)
Discussion started by: dhirajdsharma
2 Replies

7. Shell Programming and Scripting

Script not giving o/p

Hi Below is snippet from script which is not giving the o/p.script name is alarm.sh #!/bin/sh out=`awk '(NR>1) {print $9;exit}' alarm` echo $a however when i simply run the above command i an getting the o/p $ out=`awk '(NR>1) {print $9;exit}' alarm` $ echo $a 6... (2 Replies)
Discussion started by: scriptor
2 Replies

8. Shell Programming and Scripting

Awk: Comparing arguments with in line values of file and printing the result

I need to develop a script where I will take two date arguments as parameter date1 and date2 which will in format YYYYMM. Below is the input file say sample.txt. sample.txt will have certain blocks starting with P1. Each block will have a value 118,1:TIMESTAMP. I need to compare the... (7 Replies)
Discussion started by: garvit184
7 Replies

9. Shell Programming and Scripting

Grep command giving different result for different users for same command

Hello, I am running below command as root user #nodetool cfstats tests | grep "Memtable switch count" Memtable switch count: 12 Where as when I try to run same command as another user it gives different result. #su -l zabbix -s /bin/bash -c "nodetool cfstats tests | grep "Memtable switch... (10 Replies)
Discussion started by: Pushpraj
10 Replies

10. Shell Programming and Scripting

CUT command not giving correct result inside loop

Hi, i have a source file and have 3 columns and separated by "|" .i want to split this 3 columns in different variable.When i am executing this values indivisually giving correct result but when the same execute inside a for loop,it's giving issues. Src file(jjj.txt) -------... (8 Replies)
Discussion started by: raju2016
8 Replies
IN_ARRAY(3)								 1							       IN_ARRAY(3)

in_array - Checks if a value exists in an array

SYNOPSIS
bool in_array FALSE (mixed $needle, array $haystack, [bool $strict]) DESCRIPTION
Searches $haystack for $needle using loose comparison unless $strict is set. PARAMETERS
o $needle - The searched value. Note If $needle is a string, the comparison is done in a case-sensitive manner. o $haystack - The array. o $strict - If the third parameter $strict is set to TRUE then the in_array(3) function will also check the types of the $needle in the $haystack. RETURN VALUES
Returns TRUE if $needle is found in the array, FALSE otherwise. EXAMPLES
Example #1 in_array(3) example <?php $os = array("Mac", "NT", "Irix", "Linux"); if (in_array("Irix", $os)) { echo "Got Irix"; } if (in_array("mac", $os)) { echo "Got mac"; } ?> The second condition fails because in_array(3) is case-sensitive, so the program above will display: Got Irix Example #2 in_array(3) with strict example <?php $a = array('1.10', 12.4, 1.13); if (in_array('12.4', $a, true)) { echo "'12.4' found with strict check "; } if (in_array(1.13, $a, true)) { echo "1.13 found with strict check "; } ?> The above example will output: 1.13 found with strict check Example #3 in_array(3) with an array as needle <?php $a = array(array('p', 'h'), array('p', 'r'), 'o'); if (in_array(array('p', 'h'), $a)) { echo "'ph' was found "; } if (in_array(array('f', 'i'), $a)) { echo "'fi' was found "; } if (in_array('o', $a)) { echo "'o' was found "; } ?> The above example will output: 'o' was found SEE ALSO
array_search(3), isset(3), array_key_exists(3). PHP Documentation Group IN_ARRAY(3)
All times are GMT -4. The time now is 09:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy