LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-29-2008, 05:45 PM   #1
babag
Member
 
Registered: Aug 2003
Posts: 419

Rep: Reputation: 31
bash syntax question


i need to run dos2unix on a file to fix some line endings
from a wxp text file. i'm trying to do this from a script.
what's the syntx to do this? i have this:
Code:
./dos2unix /home/user_account/documents/file_to_process.txt
this is producing an error. what did i get wrong?

thanks,
BabaG
 
Old 05-29-2008, 06:01 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
What error is it producing? Have you looked at the man page? You need to specify an output file. The following is from http://linux.die.net/man/1/dos2unix:
Code:
dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]
 
Old 05-29-2008, 06:09 PM   #3
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
actually, i just cd'ed to the file's directory and did a test by typing:
Code:
dos2unix filename_to_process.txt
into a terminal and the resultant file became usable so that was as far
as i ever took it. i'm just trying to replicate that from a script now.

the file is a txt file which i'm parsing. it carries a lot variable
values for another app. once i've moved it into my mandriva box i just
need to get rid of the extra windows characters at the line ends for
my app to be able to run. my first test worked fine with no extra
parameters or anything, just the line above.

thanks,
BabaG
 
Old 05-29-2008, 06:19 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Code:
./dos2unix
Is the dos2unix binary in the current working directory? Because that's where bash is looking for it.
 
Old 05-29-2008, 06:29 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by David the H. View Post
Code:
./dos2unix
Is the dos2unix binary in the current working directory? Because that's where bash is looking for it.
If he's having such a problem with such a simple thing, I'd try to be more explicit when answering.

babag, you need to remove the ./ on the script, in other words, the contents of the script should be this:

Code:
#!/bin/bash
dos2unix /path/to/filename.txt
I added the shabang of the first line for the sake of correctness. Still, I can't understand the purpose of this script, unless it's just for educational purposes.

Feel free to ask anything else if this is not the info you needed.

Cheers.
 
Old 05-29-2008, 06:40 PM   #6
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
tried:
Code:
./usr/bin/dos2unix /path/to/file.txt
but got error that the file does not exist:
Code:
/home/processing-01/Documents/Scripts/d2u_and_nconvert.sh: line 5 ./usr/bin/dos2unix: No such file or directory.
i'm starting to think that this is a more complex issue having to do with ssh.

it's true that on my local box /usr/bin/dos2unix does not exist.

script 1 on my local box calls dos2unix_and_nconvert.sh on a remote box,
though. that's when i get the error. i'm wondering if things are confused
between the two boxes and the error is referring to the local box?

will post an ssh question on the networking forum.

thanks,
BabaG

Last edited by babag; 05-29-2008 at 06:44 PM.
 
Old 05-29-2008, 06:45 PM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by babag View Post
tried:
Code:
./usr/bin/dos2unix /path/to/file.txt
but got error that the file does not exist:
Code:
/home/processing-01/Documents/Scripts/d2u_and_nconvert.sh: line 5 ./usr/bin/dos2unix: No such file or directory.
i'm starting to think that this is a more complex issue having to do with ssh.

it's true that on my local box /usr/bin/dos2unix does not exist.

script 1 on my local box calls dos2unix_and_nconvert.sh on a remote box.
that's when i get the error. i'm wondering if things are confused between
the two boxes and the error is referring to the local box?

thanks,
BabaG
Try what I posted above, you are unnecessarily adding complexity. dos2unix is a standard tool which is in the system path 100% of the times (unless it's not installed).

"./usr/bin/dos2unix" means "go to usr/bin starting from the current dir, and look for an executable file called dos2unix"

In other words, if you log in with the user name "i92", your path is translated as "/home/i92/usr/bin/dos2unix". So, again, remove the path, leave just "dos2unix".

I am assuming that the machine you are login to has this tool installed, if not, you will need to either add it to some dir on your home dir which is in your $PATH, ask your admin to install it for you globally or implement this in any other way (there are more ways).

Last edited by i92guboj; 05-29-2008 at 06:47 PM.
 
Old 05-29-2008, 06:59 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As mentioned above, dos2unix is normally in the list of dirs in your PATH shell variable.


./blah/blah

'./' means start in the current dir (ie where your shell is pointing when you run the cmd), so in

./usr/bin/dos2unix

its saying; starting in the current dir (.), look for a subdir called usr, look in there for a subdir bin and look in there for a prog dos2unix.

if you had

/usr/bin/dos2unix

that means start at the root dir (/), ie root of the filesystem and work down as described above.
Note that the root dir has nothing to do with the root user.


FYI, '.' means current dir, '..' means parent dir (ie 1 above the current dir).

http://rute.2038bug.com/index.html.gz
 
Old 05-29-2008, 08:42 PM   #9
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
removing the '.' at the start seems to have done it.
have another issue as i'm unsure dos2unix actually ran,
but i'm at least past that error.

{edit}
it appears that dos2unix did not run. i had a copy of
the text file sitting around that i had previously run
dos2unix on. first i tried to manually run my processing
app on the remote and it produced a segmentation error.
then i switched the textfile for the one i knew dos2unix
had been run on. ran the processing app again. no error.

looks like, while i've managed to remove the error when i
try to run dos2unix from my script, dos2unix does not
actually run.

thanks!
BabaG

Last edited by babag; 05-29-2008 at 08:52 PM.
 
Old 05-29-2008, 11:26 PM   #10
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by babag View Post
looks like, while i've managed to remove the error when i
try to run dos2unix from my script, dos2unix does not
actually run.
Re-read my posts. That means that it's not installed on the server. I told you above the options you have on that case.
 
Old 05-29-2008, 11:56 PM   #11
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
thanks, i92guboj. let me see if i have this right.

i know that dos2unix is installed on the remote boxes that
are being called. the textfile that needs to be changed by
dos2unix is also on the remote boxes. since i know they are
both there, and i know it's not working, are you saying that
i need for dos2unix to be installed on the local box? that's
where the call is being made from. are you saying that the
local installation of dos2unix would be doing the processing
of the remote text file? that's all i can figure since i
know both dos2unix and the textfile are on the remote box.
sorry for being so obtuse, but this ssh stuff is a kind of a
mindbender for this n00b, especially with scripts calling other
scripts and the like.

thanks for your patience. i'm rereading your posts.
BabaG
 
Old 05-30-2008, 12:04 AM   #12
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by babag View Post
thanks, i92guboj. let me see if i have this right.

i know that dos2unix is installed on the remote boxes that
are being called. the textfile that needs to be changed by
dos2unix is also on the remote boxes. since i know they are
both there, and i know it's not working, are you saying that
i need for dos2unix to be installed on the local box?
No, as long as you are logged via ssh onto a remote box, then all the tools you invoke will run on that box. You don't need anything in local.

Anyway, to try to debug the issue, can you try manually loging in via ssh and then running dos2unix manually there? That could help us to understand what the problem is, if any.


Don't hesitate to ask as many times as you need. As long as you put some effort on your side I don't have a problem on giving some minutes of mine either.

cheers.
 
Old 05-30-2008, 12:31 AM   #13
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
thanks so much for your time i92guboj. i'm actually not
at the site now and have pretty much exhausted what i can
do without being at the boxes. will try as you suggest
tomorrow when i get in. wil try running dos2unix locally
as well as via a manual ssh login. won't be for 14 or 15
hours, though.

thanks again,
BabaG

Last edited by babag; 05-30-2008 at 12:33 AM.
 
Old 05-30-2008, 04:59 PM   #14
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
ok. new info. tried three things, one of which seems to work in some fashion.

first, i connected to the remote manually via ssh:
Code:
ssh user_acct@ip_address
i then tried each of these three things:
Code:
/home/user_acct/Documents/Scripts/d2u_and_nconvert.sh
which produced an error:
Code:
-bash: ./home/user_acct/Documents/Scripts/d2u_and_nconvert.sh: No such file or directory
then i tried removing the '.' at the start of the command:
Code:
./home/user_acct/Documents/Scripts/d2u_and_nconvert.sh
which seemed to sort of run it but not correctly. the output to screen that the script
should have made was basically there but things were a bit off and the processing of files
never happened. filenames were wrong and such. that's why they never got processed. the
names were output to screen as if they were processing but were missing characters like
'-'. that meant i could see the script was trying to run but had incorrect filename info so
they never got processed.

i then manually navigated to the folder containing the script:
Code:
cd /home/user_acct/Documents/Scripts
and, from there, ran the script:
Code:
./d2u_and_nconvert.sh
this actually worked. the filenames displayed correctly on the screen ands the processing
did occur.

so, i guess my question would be how to interpret this into my script:

connection was made manually via ssh using the same ssh command as earlier indicated.
script directory was manually navigated to.
script was manually run from within its directory.

so... now what?

thanks,
BabaG
 
Old 05-30-2008, 05:15 PM   #15
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
apologies. been trying to edit my last post to swap the
first two examples of things i tried because i, obviously,
inverted them. the ./ was the first thing and th / was
the second. whenever i try to edit them, though, my
connection times out. sorry. something odd is going on
with my dsl line in this studio.

BabaG
 
  


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
bash syntax problems hashbangbinbash Linux - Newbie 4 04-15-2008 08:03 AM
bash, syntax error santana Linux - Software 2 01-23-2008 01:39 PM
bash syntax Sushy Programming 1 06-04-2007 06:25 PM
BASH : syntax error semaja2 Programming 6 01-26-2006 12:33 AM
explanation on some bash syntax slzckboy Programming 2 10-02-2005 06:06 AM

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

All times are GMT -5. The time now is 11:16 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