LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2011, 09:05 AM   #1
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Rep: Reputation: 0
Question script showing control sequences in list of filenames


Afternoon,

as part of a script to generate commands for a number of files, I'm using the basic command below:

-----------
for file in `ls -1 *.bd`
do
echo "proutil dbname -C load $file" >> $log
done

----------
Seems simple enough, but the script is inserting control sequences in the file
part of the command
i.e. a file called access.bd becomes

^[[0m^[[0maccess.bd^[[0m

Any suggestions as to how I can stop this happening would be appreciated.

TIA,

DG.
 
Old 06-07-2011, 09:14 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The control sequences are probably due to the ls command aliased to show colors. You can either escape the command to run the unaliased ls:
Code:
for file in `\ls -1 *.bd`
do
  echo "proutil dbname -C load $file" >> $log
done
or even better without the ls command at all:
Code:
for file in *.bd
do
  echo "proutil dbname -C load $file" >> $log
done
 
Old 06-07-2011, 09:18 AM   #3
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
thanks for the response Colucix, but neither is preventing the control sequences appearing.
 
Old 06-07-2011, 09:21 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Really strange. Please, can you post the output of the following, to see what exactly are these control sequences?
Code:
for file in *.bd
do
  echo $file | od -c
  break
done
 
Old 06-07-2011, 09:30 AM   #5
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
the results of the octal dump were
0000000

Hopefully this tells you more than it tells me :-)
 
Old 06-07-2011, 09:38 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by danishgambit View Post
the results of the octal dump were
0000000
Hmmm... most likely you were not in the directory containing the *.bd files. The result of od is empty.
 
Old 06-07-2011, 09:43 AM   #7
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
Just in case I was in the wrong directory, I've just double checked by running it again, and still getting the same output

0000000

Cheers,

DG.
 
Old 06-07-2011, 10:19 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Just so we are on the same page, you are running this on some form of linux and the shell is either bash or sh?

Your output seems to be a bit bogus as even if I run the following:
Code:
$ echo | od -c
0000000  \n
0000001
So assuming you get in the loop and the variable has nothing in it, you should at least get the above.
If you are running colucix's code then you are also in a directory where there are no files or directories ending in '.bd'
 
Old 06-16-2011, 05:18 AM   #9
danishgambit
LQ Newbie
 
Registered: Sep 2009
Location: glasgow, scotland
Posts: 25

Original Poster
Rep: Reputation: 0
thanks for the input chaps. Just realised that I may have been wasting your time. I'd assumed it was a linux box (as our boxes are always linux), but this one is apparently solaris, so I guess that might explain it.

Anyway, on the assumption that this is the reason, I'll mark this call as closed.

Thanks again.
 
Old 06-16-2011, 05:24 AM   #10
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
for file in `ls *.bd`
do
echo "proutil dbname -C load $file" >> $log
done

could you please try this.. I have removed ls "-1" from it.. Just out of curiosity.

Last edited by ssrameez; 06-16-2011 at 05:25 AM.
 
Old 06-16-2011, 05:48 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by danishgambit View Post
thanks for the input chaps. Just realised that I may have been wasting your time. I'd assumed it was a linux box (as our boxes are always linux), but this one is apparently solaris, so I guess that might explain it.

Anyway, on the assumption that this is the reason, I'll mark this call as closed.

Thanks again.
I can move the thread to the Solaris/Opensolaris forum. But have you solved the problem? If not, please show us the output of
Code:
ls -l *.bd
does it show colored in the terminal?

Last edited by colucix; 06-16-2011 at 05:49 AM.
 
Old 07-15-2011, 06:16 AM   #12
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by danishgambit View Post
thanks for the input chaps. Just realised that I may have been wasting your time. I'd assumed it was a linux box (as our boxes are always linux), but this one is apparently solaris, so I guess that might explain it.
There is no reason for Solaris to behave differently than Linux on this issue.

This should just work even with the legacy Solaris bourne shell:
Code:
for file in `ls *.bd`
do
      echo "proutil dbname -C load $file" >> $log
done
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
list filenames with spaces in a shell script xp_newbie Programming 6 03-15-2009 07:46 PM
script help - add absolute path to list of filenames greengrocer Linux - Newbie 7 10-12-2008 04:23 AM
script to list the filenames which are in lower case naveensankineni Programming 2 03-12-2008 07:09 AM
Uppercase filenames showing in lowercase rvoigt Linux - General 1 02-20-2006 11:07 PM
Knoppix 3.9 not showing Windows long filenames jhenry458 Linux - Newbie 3 08-17-2005 12:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:43 PM.

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