Slackware This Forum is for the discussion of Slackware Linux.
|
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
|
03-07-2014, 06:38 AM
|
#16
|
Member
Registered: Feb 2013
Posts: 419
Rep:
|
you can also use this
|
|
|
03-07-2014, 06:57 AM
|
#17
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
|
Quote:
Originally Posted by colucix
If you use quotes the whole list is taken as a single word! To avoid problems with blank spaces, either change the IFS variable or use a while read loop, redirecting standard input from <(find Aver*).
|
I get
Code:
semoi@server:~/STORE1/Nonsoft/libros/chess/nuevo$ cat ren2.sh
while read INPUT
do
echo "$INPUT"
done < (find Aver*)
semoi@server:~/STORE1/Nonsoft/libros/chess/nuevo$ ./ren2.sh
./ren2.sh: line 36: syntax error near unexpected token `('
./ren2.sh: line 36: `done < (find Aver*)'
semoi@server:~/STORE1/Nonsoft/libros/chess/nuevo$
What can the syntax error be?
|
|
|
03-07-2014, 07:04 AM
|
#18
|
Senior Member
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Rep:
|
RTFM. "Note that no space may appear between the < or > and the left parenthesis, otherwise the construct would be interpreted as a redirection."
In any case I would always prefer 'find Aver* | while read...' instead of 'while ... do ... done <(find...)' because it preserves left-to-right readability.
But then I wouldn't use while read at all... and if you're going to use find instead of ls, you might as well use -print0...
|
|
|
03-07-2014, 07:27 AM
|
#19
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
|
still gets syntax error. I am using 'for i in Aver*' as suggested by Colucix. That worked. Damned filenames with spaces!
|
|
|
03-07-2014, 07:40 AM
|
#20
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by stf92
|
It should be
Code:
done < <(find Aver*)
spaced as shown. The first < is input redirection, whereas <(command) is process substitution.
|
|
1 members found this post helpful.
|
03-07-2014, 07:54 AM
|
#21
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
|
Thank you very much, colucix.
|
|
|
03-07-2014, 08:19 PM
|
#22
|
Senior Member
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,860
|
Quote:
Originally Posted by 55020
IFS is a game you can't win. Choose any random character that you *can't* have in your filenames. Are you feeling lucky?
|
I thought that was why there's a -print0 option to find.
|
|
|
03-09-2014, 05:39 AM
|
#23
|
Member
Registered: Apr 2010
Distribution: Slackware
Posts: 497
Rep:
|
Quote:
Originally Posted by stf92
Hi: I have a set of files under the same directory, all filenames beginning with the same prefix. How could I take away the prefix from all the filenames?
All I need is a way to do the operation for only one file, as then I could write a script to do the same within a loop.
|
I don't understand the complexity of replies in this thread. I habitually do that with one line of bash code:
Code:
for file in oldprefix* ; do mv $file newprefix${file#oldprefix} ; done
just have a look at the bash man page under "Parameter Expansion".
|
|
|
All times are GMT -5. The time now is 02:32 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|