bash - Adding double quotes to last field of ls command output -
i writing shell script , files(zip) in directory using ls command , unzip them in destination , problem file name having spaces between ,so when script scanning considering name after space
example: if file name "a b c.zip" , c.zip considered file name , file not found.
so please let me know how handle
i thought if can enclose file name in double quotes should work.so looking how can add double quote last field of ls command . need field of ls command since checking file size , timestamp before unzip ,so need enclose file name double quotes last field of ls command.
regards, sathya
i'd suggest use bash's wildcard patterns (which deal white spaces you) file list , use stat
command info specific file. example:
$ ls -l total 1 -rw-r--r-- 1 root root 0 2013-03-25 16:27 b c.txt -rw-r--r-- 1 root root 0 2013-03-25 16:27 d e f.txt $ file in *.txt; stat "$file"; done file: `a b c.txt' size: 0 blocks: 1 io block: 131072 regular empty file device: 3dd0002h/64815106d inode: 455629 links: 1 access: (0644/-rw-r--r--) uid: ( 0/ root) gid: ( 0/ root) access: 2013-03-25 16:27:35.388291856 +0800 modify: 2013-03-25 16:27:35.388291856 +0800 change: 2013-03-25 16:27:35.388310939 +0800 file: `d e f.txt' size: 0 blocks: 1 io block: 131072 regular empty file device: 3dd0002h/64815106d inode: 455630 links: 1 access: (0644/-rw-r--r--) uid: ( 0/ root) gid: ( 0/ root) access: 2013-03-25 16:27:35.388401772 +0800 modify: 2013-03-25 16:27:35.388401772 +0800 change: 2013-03-25 16:27:35.388412772 +0800 $
note stat
has --format
option can tell give info interested in files.
Comments
Post a Comment