Quote:
Originally posted by mathias1979
Two quick questions about shell, or c-shell scripting. Is there a command that will read the names of all files in a particular directory into an array so that I may loop through those files with my script without having to manually enter their names? Also, how would I go about reading just a portion of a character string into a new variable. For instance, if I had the character string "file02" stored in a variable...how could I read just the last two characters ('02') into a new variable?
-Matt
|
I only know bash (sh in most cases is a link to bash)
Question one:
Code:
for name in *; do ......done
be carefull and protect $name variable with " " because the filenames may contain spaces
question two:
first approach: (cutting off a part from the begging of a string that fits in a pattern)
Code:
skalkoto@darkstar:~$ var="file02"
skalkoto@darkstar:~$ var1=${var#file}
skalkoto@darkstar:~$ echo $var1
02
skalkoto@darkstar:~$
second approach: (using the string position)
Code:
skalkoto@darkstar:~$ var="file02"
skalkoto@darkstar:~$ var2=${var:4}
skalkoto@darkstar:~$ echo $var2
02
skalkoto@darkstar:~$