PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Using basename to strip suffix
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Using basename to strip suffix

Réponse
 
LinkBack Outils de la discussion
Vieux 28/05/2007, 02h12   #1
Dave Kelly
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Using basename to strip suffix

I am trying to strip the suffix 'jpg' from a list of images. I keep
getting this error.

../writeimage: line 23: and this is what you catch.jpg: command not found
../writeimage: line 23: dave-damon-2006-3.jpg: command not found
../writeimage: line 23: Double exposure.jpg: command not found

Here is a snippet containing the error producing code.

for filename in *.jpg; ##list images in directory

do
if [ -f "$filename" ]
then

CAPTION=basename "$filename" .jpg

imageline="
<td align=\"center\"> <p style=\"margin-top: 0; margin-bottom: 0\"> <img
border=\"0\" src=\"$filename\"></a></p> <p style=\"margin-top: 0;
margin-bottom: 0\">"$CAPTION"</p> </td>"

This is a maintance tool for me. I run it on my debian based machine.

TIA
Dave

--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.
  Réponse avec citation
Vieux 28/05/2007, 02h54   #2
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using basename to strip suffix

Dave Kelly wrote:
> I am trying to strip the suffix 'jpg' from a list of images. I keep
> getting this error.
>
> ./writeimage: line 23: and this is what you catch.jpg: command not found
> ./writeimage: line 23: dave-damon-2006-3.jpg: command not found
> ./writeimage: line 23: Double exposure.jpg: command not found
>
> Here is a snippet containing the error producing code.
>
> for filename in *.jpg; ##list images in directory
>
> do
> if [ -f "$filename" ]
> then
>
> CAPTION=basename "$filename" .jpg


CAPTION=$( basename "$filename" .jpg )

or using shell builtins instead of costly external processes...

CAPTION=${filename%.jpg}


Janis

>
> imageline="
> <td align=\"center\"> <p style=\"margin-top: 0; margin-bottom: 0\"> <img
> border=\"0\" src=\"$filename\"></a></p> <p style=\"margin-top: 0;
> margin-bottom: 0\">"$CAPTION"</p> </td>"
>
> This is a maintance tool for me. I run it on my debian based machine.
>
> TIA
> Dave
>

  Réponse avec citation
Vieux 28/05/2007, 04h02   #3
Dave Kelly
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using basename to strip suffix

Janis Papanagnou wrote:

> CAPTION=$( basename "$filename" .jpg )
>
> or using shell builtins instead of costly external processes...
>
> CAPTION=${filename%.jpg}
>
>
> Janis


Worked like a charm. Thanks.
Where would I go to read/learn about some of this stuff. A google search
did not turn up any interesting leads.
Is there a better place than 'info coreutilities'? Does this cover builtins?

Thanks again.
Dave


--
A little rum in the morning coffee. Just to clear the cobwebs, ya know.
  Réponse avec citation
Vieux 28/05/2007, 13h07   #4
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using basename to strip suffix

Dave Kelly wrote:
> Janis Papanagnou wrote:
>
>> CAPTION=$( basename "$filename" .jpg )
>>
>> or using shell builtins instead of costly external processes...
>>
>> CAPTION=${filename%.jpg}
>>
>>
>> Janis

>
>
> Worked like a charm. Thanks.
> Where would I go to read/learn about some of this stuff. A google search
> did not turn up any interesting leads.
> Is there a better place than 'info coreutilities'? Does this cover
> builtins?


The builtins depend on the used shell, for Kornshell for example you can
find the information in the manpage online
http://www.cs.princeton.edu/~jlk/kor...doc/man93.html
or for bash with man bash. Though careful about portability; even most
modern shells have a large common subset you may occasionally want
to restrict to the POSIX subset. (The above ${...%...} is POSIX.) Surely
the man pages are a good source to get an overview of the shell features.

Janis

>
> Thanks again.
> Dave
>
>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h36.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11906 seconds with 12 queries