LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2011, 10:48 AM   #1
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Rep: Reputation: 15
Need help with my Bash Script


Code:
#!/bin/bash

#checks current users folder for hidden file of .xlpr
if [ -e ~/.xlpr ];
then
	#If it exists, then tells the user it has already run
        echo "Setup has already been ran."
else
        #If no, then asks for the username
	echo "Please type the username you wish to print with, followed by [ENTER]:"
	read uname

	echo $uname > ~/.xlpr
fi
That is the code for script named XLPR-Setup. I have then ran chmod 700 XLPR-Setup. However, when I try to run it, it tells me "Bad command or file name". I am attempting to use this on CentOS LiveCD under /home/CentOS.

What am I doing wrong with it?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-04-2011, 10:53 AM   #2
goossen
Member
 
Registered: May 2006
Location: Bayern, Germany
Distribution: Many
Posts: 224

Rep: Reputation: 41
It works OK for me.
 
Old 02-04-2011, 11:12 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

What is the output of the following command: od -c XLPR-Setup | head -5
 
Old 02-04-2011, 11:35 AM   #4
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Original Poster
Rep: Reputation: 15
0000000 # ! / b i n / b a s h \r \n i f
0000020 [ - e ~ / . x l p r ] ; \r
0000040 \n t h e n \r \n \t e c h o " S e
0000060 t u p h a s a l r e a d y
0000100 b e e n r a n . " \r \n e l s e
 
Old 02-04-2011, 11:36 AM   #5
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by goossen View Post
It works OK for me.
is it because I am trying to running it on the LiveCD instead of the full install? and did you just do chmod 700 XLPR-Setup?
 
Old 02-04-2011, 11:45 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,
Quote:
Originally Posted by HyperTrey View Post
0000000 # ! / b i n / b a s h \r \n i f
0000020 [ - e ~ / . x l p r ] ; \r
0000040 \n t h e n \r \n \t e c h o " S e
0000060 t u p h a s a l r e a d y
0000100 b e e n r a n . " \r \n e l s e
The bold parts, line terminator/carriage return, show that this is not a regular linux/unix file (would be: \n \n) but a dos file (\r \n), which is also the reason why your script doesn't behave as expected.

How did you create this file?

A fast solution: dos2unix XLPR-Setup it should be fixed now.

Hope this helps.
 
2 members found this post helpful.
Old 02-04-2011, 12:11 PM   #7
HyperTrey
Member
 
Registered: Sep 2006
Posts: 127

Original Poster
Rep: Reputation: 15
OK, I gotcha ya. I wrote it in windows as that was all I had at the time (NotePad++). So if I write it in a linux environment it will be fine. Is there a windows application that will allow me to write in a linux file? Sometimes I only have windows to write my stuff.

I do apologize, I am a linux novice. I write alot of perl, just not Linux stuff.
 
Old 02-04-2011, 12:20 PM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

You can use (g)vim. Also available for other OS flavours. Maybe there are other window specific program, but I cannot help you with that one.

Quote:
I do apologize, I am a linux novice.
No need to apologize, we all where novice at one point

If this is solved, can you put up the tag (First post -> Thread Tools).
 
1 members found this post helpful.
Old 02-04-2011, 12:24 PM   #9
Acron_0248
Member
 
Registered: Feb 2006
Location: Venezuela
Distribution: Gentoo
Posts: 453

Rep: Reputation: 33
Also, notepad++ and most windows editors have an option that allows you to convert a file to unix format, can't remember exactly where that option is though :-/
 
Old 02-05-2011, 02:33 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I now this has already been marked as SOLVED, but I thought I would just point out that using an existing command name as a variable name can prove error prone later on.
Code:
read uname
If you do a man uname you will see what this function does. In the scope of your script I do not see this possibly being an issue, but thought I would just point it out
 
  


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
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 08:37 AM
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
[SOLVED] Setting function default in a bash script - Bash sixtensixone Linux - General 13 01-08-2011 01:44 PM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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