LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-01-2021, 07:09 AM   #16
postcd
Member
 
Registered: Oct 2013
Posts: 527

Original Poster
Rep: Reputation: Disabled
Lightbulb


Quote:
Originally Posted by shruggy View Post
I'd do it with mapfile instead
thank you, it worked. I only replaced "select line" by "select i" as i am using variable $i later in the script.
 
Old 04-01-2021, 07:29 AM   #17
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
The select statement in Bash is nice, but rather limited. Anyway, you're OK as long as it covers your needs. For more precise and sophisticated menu control I'd rather use something like smenu, pick, or write my own menu handling function. I hesitate to recommend iselect as it is less flexible than smenu and was not updated in ages. OTOH, depending on your needs it's also could still be useful.

Some random thoughts.
  1. Quote:
    Originally Posted by postcd View Post
    IFS=$(echo -e '\n')
    It's not needed for mapfile, but I want to comment on this nevertheless. You're using select which is a Bash-specific feature anyway. Bash has the ANSI-C quoting ($'string'). IFS=$'\n' is the usual Bash incantation for this. But even if you prefer to stay POSIX-conform, the right way to assign newline to IFS would be
    Code:
    IFS=${IFS#??}
    This works because according to POSIX, the default value of IFS is <space><tab><newline> in this exact order.

  2. Judging by your troubles to get this right, I'd suggest you read up on how to parse file names.

Last edited by shruggy; 04-01-2021 at 10:18 AM.
 
Old 04-01-2021, 12:28 PM   #18
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,791

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Nothing against the bash-specific
Code:
  IFS=$'\n'
But already the old Bourne shell allowed a physical newline inside a 'string' or "string"
Code:
  IFS="
"
 
Old 04-06-2021, 01:22 AM   #19
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As per ScottieH
Quote:
Linux uses white-space as a word separator
so don't do that..

Seriously, unless you want to spend the rest of your programming life escaping spaces / quoting vars, which is tedious to type and painful to read, start by renaming the files .
Classically, substitute underscores for the spaces. After that, things will be much easier.

Also, use multiple lines for your code; don't try to jam it all on one line.
Again, it's hard to read and even harder to debug.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command line syntax - No such file or directory exists Mountaineer Linux - Newbie 11 11-06-2011 03:09 PM
I question on a bash script and filename spaces... trist007 Programming 13 01-17-2010 06:13 AM
/bin/cp cannot stat "filename" no such file name or directory fcfury Linux - Newbie 2 07-01-2009 09:21 AM
Bash script to remove capitalisation and spaces form a filename scuzzman Programming 11 05-18-2008 12:28 PM
bash, cp and filename (with spaces) woes dfidler Programming 9 04-10-2007 11:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration