Computing.Net > Forums > Unix > multiple filename as argument

multiple filename as argument

Reply to Message Icon

Original Message
Name: phgct2004
Date: May 18, 2004 at 20:13:28 Pacific
Subject: multiple filename as argument
OS: Redhat 9.0
CPU/Ram: 866/128
Comment:

hi all,

i have face new prolem in writing my bash script. my problem is that i want to write a script that will accept any number of arguments and return the newest file from the list. and i only manage to compare the file using

file1 -nt file2

the problem is that how can i write a script that can accept multiple filename as argument and have a check whether such file is exit or not.

thank,
regard,

chui


Report Offensive Message For Removal


Response Number 1
Name: phgct2004
Date: May 18, 2004 at 21:08:04 Pacific
Subject: multiple filename as argument
Reply: (edit)

hi,

i have manage to check the multiple file as argument that key in by the user already but the problem is that my coding that compare the newest file not work when the argurment is passing. below is my coding and can anybody tell me what wrong with my bash script and have a correction for me. thank

#!/bin/bash

if [ $# -ne 2 ]
then
echo 'At least two argument is required' >&2
echo "Usage: ${0##*/} file1 [file2 file3 ...]" >&2
exit 1
fi

newfile=0

for x in $*
do
if [ $1 -nt newfile ]; then
newfile=$1
fi
shift
done

echo "The newest file in the list is : $newfile"

after i key in the file name and the arguments the result give me is 0. help me pls.

thank
regard

chui


Report Offensive Follow Up For Removal

Response Number 2
Name: Dlonra
Date: May 19, 2004 at 05:47:33 Pacific
Subject: multiple filename as argument
Reply: (edit)

new to scripts?

newfile=""

for x in $*
do
if [ $x -nt $newfile ]; then
newfile=$x
fi



Report Offensive Follow Up For Removal

Response Number 3
Name: linuxbaby
Date: January 6, 2006 at 01:46:18 Pacific
Subject: multiple filename as argument
Reply: (edit)

i'm confused about this script too ... any expert can give solution !!
Thk alot ..........


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: multiple filename as argument

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software