LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-03-2006, 08:34 AM   #1
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Rep: Reputation: 15
Question (bash) echo "#!/bin/bash" event not found - trying to generate profiles automatically


Hi all,

I'm trying to write a simple bash script to create users on Linux and Solaris systems. Part of the spec is that I have to be able to generate a bash profile on the Solaris systems (this is done automatically on our Linux distros), so I wrote some code a bit like this:

Code:
    echo "#!/bin/bash" >> $USER_HOME.bash_profile
    echo "export PS1=\"\u@\h:\w\n$ \"" >> $USER_HOME.bash_profile
    echo "alias ll=\"ls -altr\"" >> $USER_HOME.bash_profile
However when I run that first line I get the error:

Code:
bash: !/bin/bash": event not found
So I escape the bang:

Code:
$ echo "#\!/bin/bash"
#\!/bin/bash
But as you can see the bang is still escaped in the echo'd text. Is there a better way to do this?
 
Old 05-03-2006, 08:43 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi,

Use single quotes instead of double quotes. I.e:

echo '#!/bin/bash' >> $USER_HOME.bash_profile

Or even better: Use an editor to make the script

Hope this helps.
 
Old 05-03-2006, 08:48 AM   #3
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
Yeah, I don't know what this is. Maybe it has to do with accessing the history commands. Look at this:

Code:
skalkoto@darkstar:~$ echo "#!"
echo "#"#!
##!
skalkoto@darkstar:~$
But I can provide you 2 different solutions
Either put a space between ! and /. With this:
Code:
#! /bin/bash
it's still recognized as a Bourne-Again shell script text executable.

Or even better use ' instead of ":
Code:
skalkoto@darkstar:~$ echo '#!/bin/bash'
#!/bin/bash
skalkoto@darkstar:~$

Last edited by perfect_circle; 02-10-2009 at 01:21 PM. Reason: typos
 
Old 05-03-2006, 08:50 AM   #4
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
Quote:
Originally Posted by druuna
Hi,

Use single quotes instead of double quotes. I.e:

echo '#!/bin/bash' >> $USER_HOME.bash_profile

Or even better: Use an editor to make the script

Hope this helps.
Hey! you type faster.....
 
Old 05-03-2006, 08:53 AM   #5
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
Blog Entries: 1

Rep: Reputation: 63
Quote:
Originally Posted by druuna
Or even better: Use an editor to make the script
This is, for sure, the best advice you can get.

Just to add some more information:
Create a template file, e.g. bash_profile.template and simple copy it to the home directory, changing the name in the copy command.

If you will use the useradd command, the "-m -k" options will create the home dir and copy the files from a template dir to the user's home dir.
 
Old 05-03-2006, 09:03 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi all,

I type fast, give good advice and had an excelent yearly review at work today......

Guess I'm having a good day
 
Old 05-03-2006, 09:11 AM   #7
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
Blog Entries: 1

Rep: Reputation: 63
Quote:
Originally Posted by druuna
Hi all,
I type fast, give good advice and had an excelent yearly review at work today......

Guess I'm having a good day
Congratulations !

Don't forget to try the Lotto !
 
Old 05-03-2006, 09:12 AM   #8
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Original Poster
Rep: Reputation: 15
*slaps forehead* I could have sworn I'd tried that and failed with the same result Oh well. Need more coffee I suppose.

BTW I thought of that idea of copying the profile, but you can't guarantee that the template is going to be in any specific location, especially when you're working cross platform. I had considered scp'ing it from somewhere, but this is just supposed to be a simple script and I don't want to mess around with keys or passwords.
 
Old 05-03-2006, 09:24 AM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi,

Why not use /etc/skel to store the file. Both linux and slorais (9 at least) support this. If the content of /etc/skel isn't put in the (new) homedir automatically during user creation you could try to force it with useradd's -k skeleton_dir option.

Hope this clears things up.
 
Old 05-03-2006, 10:24 AM   #10
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Original Poster
Rep: Reputation: 15
This is more just a way to configure a user on any server, until we get some kind of centralised authentication mechanism going. I don't really want to have to put a default profile on every server on the network just yet.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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: rpm: command not found" errom when trying to install any package sandeepchau123 Linux - General 16 07-06-2008 03:58 AM
bash: passwd: command not found "HELP" balweg Red Hat 4 05-05-2005 03:47 PM
"bash: run: command not found" ? neuropulse Linux - Newbie 10 04-23-2005 07:58 AM
.kde/Autostart bash scripts "file not found" Nice-n-Slow Linux - Software 1 07-02-2004 05:25 PM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM


All times are GMT -5. The time now is 03:30 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration