ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/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.
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
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.
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.
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 :-/
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.