ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
It looks like you have a different way of handling files in scripts then I do.
I usually use a loop such as
for file in <pattern>; do
mv "$file" "${file// /_}"
done
You have the output of ls in the $file variable. If you look at 'echo $file', all of the extra whitespace is removed, including the newlines. If you look at 'echo "$file"' the lines are retained. However if you try
for item in "$file"; do
echo ":$item:"
done
you will see that even though the files are printed like you want, the $item variable contains everything.
[jnsahibz@charlie jnsahibz]$ ls
CV.tar.gz Favorites assignment fidelma.txt.txt mail workspace
Desktop My Documents bin junaid.zip public_html zakir naik
now u see there is this directory MY Documents which is clearly shown as one directory and not as two.
but the problem starts from here
when i save this output into another variable. and then i try to pipe it into another command or pass it to another script instead of treating it as one directory this time it treats it as two separate directories.
huh let me try to tell this one more time.
say I have a script p
#!/bin/bash
echo "$1"
my dir listing is something like this
ls -l
total 8
-rw-rw-r-- 1 rprakash rprakash 0 Mar 28 12:18 asfd space
-rwxrwxr-x 1 rprakash rprakash 103 Mar 28 14:35 p
-rwxrwxr-x 1 rprakash rprakash 122 Mar 28 13:12 t
if I do something like this
for i in `ls`; do ./p $i; done
the output will be
asfd
space
p
t
but if I do something like
for i in "`ls`"; do ./p "$i"; done
the output will be
asfd space
p
t
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.