Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[OT] shell script [Risolti]
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Forum di discussione italiano
View previous topic :: View next topic  
Author Message
RenfildDust
Guru
Guru


Joined: 22 Nov 2003
Posts: 321
Location: Reggio Calabria - Catania - Roma

PostPosted: Sun Nov 27, 2005 11:30 pm    Post subject: [OT] shell script [Risolti] Reply with quote

Ho bisogno di manipolare una stringa in uno shell-script.
La stringa è un'indirizzo locale (file system) dove devo togliere il percorso e ottenere solo il nome del file.
Come fare?
Ho provato con cut, ma devo sapere il numero di / (cioè diretory..) a priori cosa, che non so...
_________________
La generazione di numeri casuali è troppo importante per essere lasciata al caso.


Last edited by RenfildDust on Mon Jan 02, 2006 6:38 pm; edited 2 times in total
Back to top
View user's profile Send private message
neryo
Veteran
Veteran


Joined: 09 Oct 2004
Posts: 1292
Location: Ferrara, Italy, Europe

PostPosted: Mon Nov 28, 2005 12:02 am    Post subject: Re: [leggermente OT] shell script Reply with quote

RenfildDust wrote:
Ho bisogno di manipolare una stringa in uno shell-script.
La stringa è un'indirizzo locale (file system) dove devo togliere il percorso e ottenere solo il nome del file.
Come fare?
Ho provato con cut, ma devo sapere il numero di / (cioè diretory..) a priori cosa, che non so...


Code:

# path=/prova/ciccia/pluto
# echo ${path##*/}
pluto
# path2=/prova/ciccia/paperino/pluto
#  echo ${path2##*/}
pluto

_________________
cache: a safe place for hiding or storing things..

D-link DWL-G650 AirPlus
Apache Php Mysql
Back to top
View user's profile Send private message
X-Drum
Advocate
Advocate


Joined: 24 Aug 2003
Posts: 2517
Location: ('Modica','Trieste','Ferrara') Italy

PostPosted: Mon Nov 28, 2005 12:02 am    Post subject: Reply with quote

"leggermente ot" allora posta in ot! :roll:

si usa
Code:
cut -d "/" -f n
, dove n è il numero della riga "tagliata"
per mezzo del delimitatore
_________________
"...There are two sort of lies, lies and benchmarks..."
Back to top
View user's profile Send private message
RenfildDust
Guru
Guru


Joined: 22 Nov 2003
Posts: 321
Location: Reggio Calabria - Catania - Roma

PostPosted: Mon Nov 28, 2005 12:11 am    Post subject: Reply with quote

Non conosco il numero di riga da tagliare.... altrimenti avrei risolto

comunque grazie neryo così sembra funzionare
ti devo la vita!
:P
_________________
La generazione di numeri casuali è troppo importante per essere lasciata al caso.
Back to top
View user's profile Send private message
neryo
Veteran
Veteran


Joined: 09 Oct 2004
Posts: 1292
Location: Ferrara, Italy, Europe

PostPosted: Mon Nov 28, 2005 12:13 am    Post subject: Reply with quote

RenfildDust wrote:

comunque grazie neryo così sembra funzionare
ti devo la vita!


non esageriamo.. :wink:
_________________
cache: a safe place for hiding or storing things..

D-link DWL-G650 AirPlus
Apache Php Mysql
Back to top
View user's profile Send private message
X-Drum
Advocate
Advocate


Joined: 24 Aug 2003
Posts: 2517
Location: ('Modica','Trieste','Ferrara') Italy

PostPosted: Mon Nov 28, 2005 12:15 am    Post subject: Reply with quote

RenfildDust wrote:
Non conosco il numero di riga da tagliare.... altrimenti avrei risolto
:P

dillo prima
_________________
"...There are two sort of lies, lies and benchmarks..."
Back to top
View user's profile Send private message
RenfildDust
Guru
Guru


Joined: 22 Nov 2003
Posts: 321
Location: Reggio Calabria - Catania - Roma

PostPosted: Mon Nov 28, 2005 1:50 am    Post subject: ancora una cosa... Reply with quote

Adesso ho un'altro problema..
Come faccio a trattare i files quando ci sono gli spazi?
Es:
Code:
Questo\ è\ il\ mio\ file.txt

Quando li carico su una variabile e faccio per esempio
Code:
$ cp $ARG1 $ARG2
l'interprete non si accorge degli spazi e crede siano argomenti multipli.
Ho provato apici, apici doppi e inversi, ma niente...
_________________
La generazione di numeri casuali è troppo importante per essere lasciata al caso.
Back to top
View user's profile Send private message
Cazzantonio
Bodhisattva
Bodhisattva


Joined: 20 Mar 2004
Posts: 4514
Location: Somewere around the world

PostPosted: Mon Nov 28, 2005 2:17 am    Post subject: Reply with quote

Spostato in off topic

Io leverei anche il "leggermente" dal titolo... quello che cerchi è una guida alla bash :wink:
_________________
Any mans death diminishes me, because I am involved in Mankinde; and therefore never send to know for whom the bell tolls; It tolls for thee.
-John Donne
Back to top
View user's profile Send private message
RenfildDust
Guru
Guru


Joined: 22 Nov 2003
Posts: 321
Location: Reggio Calabria - Catania - Roma

PostPosted: Mon Nov 28, 2005 2:33 am    Post subject: Reply with quote

Scusa, è che lo reputavo diverso da "che processore preferite" o simili... :oops: :oops: :oops:
_________________
La generazione di numeri casuali è troppo importante per essere lasciata al caso.
Back to top
View user's profile Send private message
skakz
Guru
Guru


Joined: 03 Jul 2004
Posts: 380
Location: Ischia/Napoli/Italia/Terra

PostPosted: Mon Nov 28, 2005 10:32 am    Post subject: Reply with quote

comunque esiste anche "basename" dagli un'occhiata...

e poi ti consiglio questa lettura :wink:
http://www.tldp.org/LDP/abs/html/


edit:
sk@omega ~ $ VAR="File di prova.txt"
sk@omega ~ $ echo $VAR
File di prova.txt
sk@omega ~ $ cp "$VAR" "$VAR"-copia
sk@omega ~ $ ls -Q
"File di prova.txt" "File di prova.txt-copia"
sk@omega ~ $
_________________
Linux Registered User n.340423
Linux User Group Ischia
www.tush.it
Back to top
View user's profile Send private message
gutter
Bodhisattva
Bodhisattva


Joined: 13 Mar 2004
Posts: 7162
Location: Aarau, Aargau, Switzerland

PostPosted: Mon Nov 28, 2005 11:00 am    Post subject: Reply with quote

Come suggeritoti dovresti usare basename.

P.S.: In accoppiata a basename c'è anche dirname.
_________________
Registered as User #281564 and Machines #163761
Back to top
View user's profile Send private message
RenfildDust
Guru
Guru


Joined: 22 Nov 2003
Posts: 321
Location: Reggio Calabria - Catania - Roma

PostPosted: Tue Nov 29, 2005 12:50 pm    Post subject: Reply with quote

darkdude wrote:
comunque esiste anche "basename" dagli un'occhiata...

e poi ti consiglio questa lettura :wink:
http://www.tldp.org/LDP/abs/html/


Sto già guardando la guida, per quanto riguarda la tua soluzione:
Quote:


edit:
sk@omega ~ $ VAR="File di prova.txt"
sk@omega ~ $ echo $VAR
File di prova.txt
sk@omega ~ $ cp "$VAR" "$VAR"-copia
sk@omega ~ $ ls -Q
"File di prova.txt" "File di prova.txt-copia"
sk@omega ~ $


E' stata la prima cosa che ho provato, ma non funziona....

in che modo dovrei usare basename?
che io sappia serve a tuttaltro...
_________________
La generazione di numeri casuali è troppo importante per essere lasciata al caso.
Back to top
View user's profile Send private message
salade
Apprentice
Apprentice


Joined: 10 May 2004
Posts: 170

PostPosted: Tue Nov 29, 2005 2:06 pm    Post subject: Reply with quote

Code:

riedi004:/home/acc01/ste>export DIR=`pwd`
riedi004:/home/acc01/ste>export FILENAME=${DIR}/test.sh
riedi004:/home/acc01/ste>echo $FILENAME
/home/acc01/ste/test.sh
riedi004:/home/acc01/ste>basename $FILENAME
test.sh
riedi004:/home/acc01/ste>dirname $FILENAME
/home/acc01/ste

Claro? ;)
Back to top
View user's profile Send private message
stefanonafets
l33t
l33t


Joined: 10 Feb 2003
Posts: 644

PostPosted: Tue Nov 29, 2005 2:10 pm    Post subject: Reply with quote

Mettiamo che tu hai una stringa col path di un file

Code:
/usr/bin/lame


e devi ottenere il nome del file, basta fare

Code:
basename /usr/bin/lame


Ma se dici che basename nn va bene, non ho capito il problema... :oops:
_________________
registered Linux user number #411324
sed 's/ke/che/g'

<The Deployment Slave is initializing>
Back to top
View user's profile Send private message
RenfildDust
Guru
Guru


Joined: 22 Nov 2003
Posts: 321
Location: Reggio Calabria - Catania - Roma

PostPosted: Mon Jan 02, 2006 6:36 pm    Post subject: Reply with quote

stefanonafets wrote:
Mettiamo che tu hai una stringa col path di un file

Code:
/usr/bin/lame


e devi ottenere il nome del file, basta fare

Code:
basename /usr/bin/lame


Ma se dici che basename nn va bene, non ho capito il problema... :oops:


Hai capito bene, e ti ringrazio. Io usavo basename per fare altro, e non pensavo che funzionasse anche così.
Io lo usavo per esempio così:
Code:
$ basename foofile.txt .txt
foofile

Grazie ancora
_________________
La generazione di numeri casuali è troppo importante per essere lasciata al caso.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Forum di discussione italiano All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum