[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Script Not Working
From: |
Dennis Williamson |
Subject: |
Re: [Help-bash] Script Not Working |
Date: |
Fri, 14 Nov 2014 13:38:07 -0600 |
On Fri, Nov 14, 2014 at 1:31 PM, nick <address@hidden> wrote:
> Sorry,
> I can attach the script here.
> #!/bin/bash
> for file in $(ls $1/ | grep -v '\.old$'); do
> echo $1
> done
> On 14-11-14 02:29 PM, Dennis Williamson wrote:
> > You say a script is not working but you don't show the script. Perhaps
> > someone will come along and do your homework assignment for you anyway.
> >
> > On Fri, Nov 14, 2014 at 10:10 AM, Nick Krause <address@hidden>
> wrote:
> >
> >> I need a script to change the files in this directory to the same file
> >> name with a .old extension. The argument to the script is the
> >> directory to use.
> >> Cheers Nick
> >> Files in directory
> >> file1 file2.old file3old file4
> >> P.S. The for loop must use grep, please don't ask why.
> >>
> >>
> >
> >
>
Never use ls and grep like that. See http://mywiki.wooledge.org/ParsingLs
for file in "$1"/*
do
if [[ $file != *.old ]]
then
mv -- "$file" "$file.old"
fi
done
(untested)
--
Visit serverfault.com to get your system administration questions answered.