[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Help With School Assignment, Learning Bash Scripts
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] Help With School Assignment, Learning Bash Scripts |
Date: |
Fri, 7 Nov 2014 08:05:30 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Thu, Nov 06, 2014 at 05:18:00PM -0500, nick wrote:
> Here is my code so far:
> !/bin/bash
> shopt -s extglob nullglob
> dir=$1
> for file in "$dir"/!*(.old)
> do
> [[ $file == *.old ]] || mv -- "$file" "$file.old"
> done
The extended glob is not quite right. If you want to match "all files
except those that end with .old" it should be "$dir"/!(*.old) instead.
Also, this makes the check for *.old inside the loop redundant.
I have to agree with Eduardo that your teacher is asking you to do things
the old, dumb, wrong way. This is tragically common from what I've seen,
and unfortunately is no longer surprising....
You'll have to choose between intentionally writing things in the broken
way that your teacher wants in order to get good grades, or doing things
the right way and explaining to your teacher why they are right, and
risking bad grades. (In this particular case you can demonstrate that
the teacher's method fails on filenames with spaces in them.)
- [Help-bash] Help With School Assignment, Learning Bash Scripts, nick, 2014/11/05
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, Eduardo A . Bustamante López, 2014/11/05
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, Eric Cook, 2014/11/05
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, Eduardo A . Bustamante López, 2014/11/05
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, Greg Wooledge, 2014/11/06
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, nick, 2014/11/06
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, Eduardo A . Bustamante López, 2014/11/06
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, nick, 2014/11/06
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts,
Greg Wooledge <=
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, Eric Blake, 2014/11/07
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, Greg Wooledge, 2014/11/07
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, nick, 2014/11/07
- Message not available
- Message not available
- Message not available
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, Greg Wooledge, 2014/11/11
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, nick, 2014/11/11
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, Greg Wooledge, 2014/11/11
- Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, nick, 2014/11/06
Re: [Help-bash] Help With School Assignment, Learning Bash Scripts, Jesse Molina, 2014/11/05