Unix Shell - newbit: what this bash script means?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > September 2006 > newbit: what this bash script means?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author newbit: what this bash script means?
wonkim

2006-09-26, 7:32 am

hi,

I want to know what this bash script part means.

if [ ! $FLIST -ef $WDIR/file.list ]; then
cp $FLIST $WDIR/file.list
fi

$FLIST contains file name string list.
$WDIR is a temporary folder name that was creadted from previous
command.
I can't understand what [ ! $FLIST -ef $WDIR/file.list ] condition
means.

Thanks!

Lew Pitcher

2006-09-26, 1:22 pm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


wonkim wrote:
> hi,
>
> I want to know what this bash script part means.
>
> if [ ! $FLIST -ef $WDIR/file.list ]; then
> cp $FLIST $WDIR/file.list
> fi
>
> $FLIST contains file name string list.
> $WDIR is a temporary folder name that was creadted from previous
> command.
> I can't understand what [ ! $FLIST -ef $WDIR/file.list ] condition
> means.


The square brackets invoke a logic test (either a link to the test(1)
binary, or the builtin condition test in your shell), so the condition
is performing an extended logical test of some conditions

! means negate the results of the test, so that TRUE becomes FALSE and
FALSE becomes TRUE.

<some_file> -ef <some_other_file> compares the two files and returns
TRUE if both files have the same device and inode number (in other
words, they are the same file or are hardlinks to the same file)

$FLIST is a shell variable. You've told us that it contains a filename
$WDIR is another shell variable. You've told us that it contains a
directoryname

Put this all togther, and
[ ! $FLIST -ef $WDIR/file.list ]
means
return a FALSE condition if the two paths point to the /same/ file,
otherwise return TRUE (if they point to /different/ files)

You /really/ need to read the manpage on your shell (i.e. bash(1) ) and
on the test(1) comand.

HTH
- --
Lew Pitcher

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32) - WinPT 0.11.12

iD8DBQFFGSFbagVFX4UWr64RAhznAKCR7sjahvy7
PIb8DgaojLleF+yuLwCdHPTn
+Lh2+3j0EIAJnr1E5MTyuzM=
=L25z
-----END PGP SIGNATURE-----

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com