echo backspace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting echo backspace
# 8  
Old 12-11-2010
@Corona688:

I want to fully understand how this lines of code do their job:
Code:
#!/bin/bash

SAVEIFS=IFS
IFS=$(echo -en "\n\b")

for f in $(cat mp3file.txt)
do
     echo "$f"
done

IFS=$SAVEIFS

I can follow everything, but I cannot follow where IFS would find a backspace as field separator. For example, to loop over a number of song titles such as these ones:
Code:
$cat mp3file.txt
01 - Don't Eat the Yellow Snow.mp3
02 - Don't Drink the Rain.mp3
03 - What is Going On?.mp3
04 - Thank You, Thank You.mp3
05 - Back to Life, Back to Theback.mp3

These are not real song titles, but just a group of names I made for testing purposes. I don't see where it is possible that IFS would find the backspace as a field separator here. I guess that is why I find it more abstract than any other.

Thanks.
--Willie

Last edited by Scott; 12-12-2010 at 04:39 AM.. Reason: Please use code tags
# 9  
Old 12-11-2010
In the ASCII world the Backspace key is not a key which generates an Escape sequence. Neither is the Linefeed key.
# 10  
Old 12-12-2010
Quote:
Originally Posted by willie
@Corona688:

I want to fully understand how this lines of code do their job:
...badly, that's how. Smilie That's a useless use of cat and prone to truncating the list should it exceed the size of a shell variable, and even when it works it's wasteful since it reads the entire list into memory, and a bit of a hack since it uses IFS and argument lists to split lines instead of using the built-in read method. It can be done much better like this:
Code:
while read f
do
        echo $f
done < mp3file.txt

As for why IFS had a backspace in it: I have no idea. The shell doesn't process backspaces specially, so maybe his data did have real, literal backspaces in it somehow, but that's not normal. It doesn't do anything for your files, since argument splitting (or read) will break on any character in IFS, not just all of them. It's not good example.

Last edited by Corona688; 12-12-2010 at 01:13 AM..
# 11  
Old 12-12-2010
Thanks a lot for the clarification Corona688.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echo backspace in spinner script

Trying to insert a backspace for echo. while true ; do i='-\|/' for j in 1 2 3 4 do echo -ne "$(echo ${i} | cut -c${j})" sleep 1 done done this currently outputs: -\|/-\|/-\|/-\| .....etc ---------- Post updated at 02:34 PM ---------- Previous update was at 02:10 PM... (7 Replies)
Discussion started by: squrcles
7 Replies

2. Shell Programming and Scripting

Using backspace in echo to show process count

i have something like this tablesName="abc def hij akn ... etc etc" count=0 for i in $tablesName do echo -en "\b\b\b\b\b\b\b\b\b\b\b\b\bTableCount: $count" count=`expr $count + 1` done the above is just a description wha i need is when the loop executes the... (1 Reply)
Discussion started by: vivek d r
1 Replies

3. Solaris

[SOLVED] Backspace not working!!!!!

Hi friends, Hope u r doing well. It is a very strange problem that I've never faced when I used linux or freebsd. When a type a command in Solaris 10, and if I make a mistake, the backspace doesn't work, when I press the backspace key three times forexample, this is what I get, ^H ^H ^H. The same... (2 Replies)
Discussion started by: gabam
2 Replies

4. UNIX Desktop Questions & Answers

backspace in vi search

Hi gurus, i use vi editor. when I want search something I Type / (or ? if i want search backward), that is OK. But when i make mistake in searching string how can i delete character ? I tried bacskpase but did not work (gives just strange characters). Also tried shift+bacskspace but this only... (3 Replies)
Discussion started by: wakatana
3 Replies

5. UNIX for Dummies Questions & Answers

how to test for backspace

Hi all, I am using a script which is as follows: It reads a character. I want to check if the character is a backspace character or some other character. read -n 1 x if ; then echo "backspace detected" else echo "some other character" fi Thanks in advance. (1 Reply)
Discussion started by: anandkumar
1 Replies

6. Solaris

Using backspace in solaris - help

Hi In solaris if i have to delete something from shell i need to use ctrl+H, coz if i use backspace it shows ^?. Can any one please tell me how to set backspace key so that i can delete any character directly instead of using Ctrl+h. Second Q is like in linux for going to recent command, i... (10 Replies)
Discussion started by: sarbjit
10 Replies

7. Shell Programming and Scripting

equivalent of backspace in ksh

Hello All, What would be the equivalent of backspace key in the korn shell. My scenario is: I am trying to install a product..and it comes out with a Licence Agreement screen, When I manually enter backspace key..I am able to get out of the whole agreement message to a point to type Agree A) or... (2 Replies)
Discussion started by: solaix14
2 Replies

8. UNIX for Dummies Questions & Answers

Control + h and Backspace

Hello, I am a UNIX newbie. With that out of that way.. In order to delete a mistyped character, I need to press control+h to move the cursor to the left, and then overwrite it. If I try hitting the backspace key, it just brings me to a new prompt. Is there a way to change it so that my... (1 Reply)
Discussion started by: martinp973
1 Replies

9. UNIX for Dummies Questions & Answers

Backspace erasing the prompt

My AIX has Korn Shell. I had set the prompt by providing assigning to PS1. If on the prompt I use backspace it erase the whatever appeared due to PS1. Can someone tell me how to forbid this erasing of prompt string, with this behaviour? Thanks in advance. (4 Replies)
Discussion started by: videsh77
4 Replies

10. UNIX for Dummies Questions & Answers

Cannot backspace on my session in CRT

Hi, when I make a mistake and then try to backspace I am unable to do so . Can someone please suggest How I can correct this on my session For Eg: pwd^H^H^H Thanks rooh (2 Replies)
Discussion started by: rooh
2 Replies
Login or Register to Ask a Question