|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Nov 2010
Messaggi: 71
|
[script bash] stampare tutti i nomi di file e directory
ciao a tutti ho il seguente problema: voglio stampare a video tutti i file e directory della stessa directory dove sta lo script bash su ubuntu. Ho usato un for in ls ma mi da un syntax error. qualcuno saprebbe aiutarmi ??? grazie
Codice:
#!/bin/sh for file in 'ls-l' do echo $file done |
|
|
|
|
|
#2 | |
|
Senior Member
Iscritto dal: Mar 2001
Città: PV Milano Nord
Messaggi: 3851
|
Quote:
__________________
"W la foca, che dio la benedoca"
poteva risolvere tutto la sinistra negli anni in cui ha governato e non l'ha fatto. O sono incapaci o sta bene anche a "loro" cosi. L'una o l'altra inutile scandalizzarsi.[plutus] |
|
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Nov 2010
Messaggi: 71
|
|
|
|
|
|
|
#4 |
|
Member
Iscritto dal: May 2011
Messaggi: 39
|
Esiste un comando apposito, ls che, dotato di appositi switch, permette di vedere tutte le info di un file. Es.. ls -i mostra anche l'i-node number, ls -a mostra anche quelli nascosti e così via...
|
|
|
|
|
|
#5 |
|
Member
Iscritto dal: Sep 2010
Messaggi: 102
|
ma soprattutto è
ls SPAZIO -l sennò non funziona |
|
|
|
|
|
#6 |
|
Member
Iscritto dal: Nov 2010
Messaggi: 71
|
ho fatto come mi avete suggerito
Codice:
#!/bin/sh for file in 'ls -l' do echo $file done non so piu cosa fare |
|
|
|
|
|
#7 | |
|
Member
Iscritto dal: Nov 2010
Messaggi: 71
|
Quote:
ls -l |
|
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Codice:
#!/bin/sh for file in `ls-l` do echo $file done oppure anche Codice:
#!/bin/sh for file in $(ls-l) do echo $file done
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
ehm, ovviamente vanno riaggiunti gli spazi... ma non riesco a modificare il post...
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
|
|
|
|
#10 | |
|
Member
Iscritto dal: Nov 2010
Messaggi: 71
|
Quote:
ESEMPIO se il file è del tipo nome 1 me lo stampa su due righe: nome 1 come posso ovviare a ciò??? |
|
|
|
|
|
|
#11 |
|
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Hai bisogno solo dei nomi o anche delle informazioni che ti da il parametro "-l" ?
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
|
|
|
|
#12 |
|
Member
Iscritto dal: Nov 2010
Messaggi: 71
|
|
|
|
|
|
|
#13 | |
|
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Quote:
SAVEIFS=$IFS IFS=$(echo -en "\n\b") for file in * ; do echo $file done IFS=$SAVEIFS
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
|
|
|
|
|
#14 | |
|
Member
Iscritto dal: Nov 2010
Messaggi: 71
|
Quote:
nel mio script uso bin/sh mentre invece tu usi bin/bash. Poi questo ifs cos è??? e sopratutto il for con * cosa si intende?? |
|
|
|
|
|
|
#15 |
|
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
IFS e' la variabile che contiene i caratteri considerati separatori per la shell expansion
http://www.faqs.org/docs/bashman/bashref_33.html In pratica ho tolto lo spazio come separatore in modo da tenere unite le parole con spazi dentro /bin/bash e' il percorso all'eseguibile di bash sui sistemi unix /bin/sh e' di solito un link a /bin/bash, per cui in realta' non cambia tanto.
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
|
|
|
|
#16 |
|
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
ah dimenticavo
ovviamente "*" e' la wildcard che viene espansa dalla shell in tutti i file della cartella corrente
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 18:20.




















