[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Help With School Assignment, Learning Bash Scripts
From: |
nick |
Subject: |
Re: [Help-bash] Help With School Assignment, Learning Bash Scripts |
Date: |
Thu, 06 Nov 2014 17:18:00 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 |
I will look into the links for learning more about shell scripting , on the
other hand I
unable to figure out how to do this part of the assignment too and have goggled
various
questions but to not valid. I will paste the parts of the question below.
Cheers Nick
1.Modify the command substitution that's being used to create the loop values
that will be placed into the "filename" variable.
Instead of just an "ls $1", pipe the output into a "grep". The "grep"
will search for all filenames that DO NOT end in ".old". This can easily
be done with the "grep -v" option.
With this approach, you can get rid of the "echo ... | grep ..." and the
"if" control structure inside the loop, and simply do the rename.
Again, check that your script works correctly.
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
On 14-11-06 08:15 AM, Greg Wooledge wrote:
> On Wed, Nov 05, 2014 at 07:46:41PM -0800, Eduardo A. Bustamante López wrote:
>> I don't want to make this explanation long, so I'll just give you
>> some links you can read on why I said that:
>>
>> -
>> http://mywiki.wooledge.org/BashGuide/TestsAndConditionals#Conditional_Blocks
>> - http://wiki.bash-hackers.org/syntax/ccmd/if_clause
>> - http://mywiki.wooledge.org/glob#extglob
>
> I'd add one more:
>
> http://mywiki.wooledge.org/BashFAQ/054 -- How can I tell whether a variable
> contains a valid number?
>
- [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 <=
- 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, 2014/11/07
- 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