Change default shell

Hi all
I am a total newbie at anything to do with shells or any form of scripting Unix/Linux etc.

I have been trying to run through a tutorial on scripting but it requires the use of sh.
My FreeNAS(FreeBSD) test box running the latest nightly build as an embedded install on CF card has csh as default.

I have been told:
FreeNAS has implemented the following shell's: sh, csh, tcsh and the latest FreeNAS 0.69b4 include bash.
The default shell for FreeNAS(FreeBSD) is csh.
For portability I'll suggest to use sh (take a look at scripts in /etc/rc.d/ directory), however bash is more advanced.

I have seen a few threads on here that suggest changing the 7th item of the relevant user in etc/passwd to the required shell.
I have edited it, saved and logout out as root and back in as the user.
If I then do
echo $shell
I get
/bin/tcsh

So it does not appear to have changed

Tried chsh, but get
Command Not Found

Have also tried one other approach, but cant seem to find the thread again, to let you know what that was, but that also gave a Command not found

I had thought of rebooting, but if I do this, as it is and embedded system, the changes get lost.

Can any one give me any pointers.

Thanks

Neil

It's not crucial that it's your login shell; you can limp along anyway. As a workaround, just exec bash immediately after you log in.

Thanks, I am sure that is true, but as I am just starting out, and wanted to run through this tutorial:
UNIX / Linux Bourne / Bash Shell Scripting Tutorial [ steve-parker.org ]

which is written with the bourne shell in mind. It is easier for me if I start from the correct shell.

That way at least I know that when something goes wrong, it is something I have done rather than a difference between the tutorial (sh) and the shell I am using (csh)

The very first line in the tutorial gets you to change the prompt to $.

The command given failed and I assumed I must have been doing something wrong. Turns out that it was the shell differences. I needed to use set prompt="$ " and not what the tutorial gave.

Since I first posted, I managed to edit the passwd file and save it to the local HDD, and using the post init command section of the FreeNAS WebGUI, managed to get it to copy across on boot up.

Still did not change the user shell though, although the edited and copied version is in /etc.

I did forget to mention that I am accessing the box remotely on the local network using PuTTy.

I tried using:
exec bash
It just closed the Putty window down immediately on hitting the RETURN key...but if it had worked, would that not have put me in a bash shell rather than sh?

On System|Advanced|Command scripts add the following command as POST:

echo bash >> /root/.cshrc

Note: This is strictly FreeNAS embedded solution/workaround.

I don't know much specifically about freeNAS, but whatever your login shell is doesn't matter as long as you declare the proper shell at the beginning of the script.
MY login shell can be sh, but if I write a korn shell script, as long as the first line in the script is #!/usr/bin/ksh, the script will be executed in korn (as long as ksh is in /usr/bin, of course).

Tried that Dan
now when logging in via Putty as root I get

bash: Command not found
test:~#

test being the name of the box

I did post another post earlier, but it did not appear, I have tried other methods, also with no result.

It now seems to have appeared after

You need 0.69b4 +, check if you have /bin/bash

No, not on this box, but sh is in there.
The test box has a nightly build on

0.7 Sardaukar (revision 3514)
built on Fri Jun 6 22:03:39 CEST 2008

Managed to create a small script just now, it creates a directory /root/.ssh and then copy the authorized_keys2 file to it, from local disk and change its permissions.
Can get it to run and work from the CLI, just trying to get it to work from PostInit in the WebGUI now.

The script in your eyes is probably the equivalent of a 3 year old child's scrawl with crayon, but at least I managed to get it to work.

No, it is not there.

I have nightly build
0.7 Sardaukar (revision 3514)
built on Fri Jun 6 22:03:39 CEST 2008
on this test box

I can always put a 0.69b4 back on.

Anyway. I have had some success.
I managed to create a small script that creates a directory, copies my authorized_keys2 file to it from a local HDD, and chmod's it.
the script, also stored on the local HDD I have got it running PostInit.
It also seems to work. Probably very childish script that you guys could have done in a much more elegant way, but it works, I have acheived something today any how.

Thanks for your help Dan, would not have done it without you.

So thanks Dan,

Neil

Edit: Sorry for the long list of posts, don't quite know what is happening, they were not there when I started this post, then after posting, they were suddenly there. Maybe the browser is pulling the page form cache rather than refreshing? I am running all from USB stick and portable apps. Any way that is not important.

I would still like to get a basic sh shell, so I can get on with the tutorial

0.7 is in alpha stage for the moment. Once FreeBSD 6.4 will be released we can release the 0.69 final and move on with 0.7.

PS: Take a look at Replace spaces - Page 2

Gulp.....wont be trying anything like that lot for a while......ever.... :slight_smile:

I was happy to get this to work and then work out the syntax to put in the PostInit line toget it to run without being in that directory

cd /root
mkdir .ssh
cp /mnt/BootDisk/authorized_keys2 /root/.ssh/
cd /root/.ssh
chmod 600 authorized_keys2

OK, so what would be a neater way of doing the above?

You don't need to cd to a directory -- any file-oriented command will accept a full path name just as well as a plain file name.

mkdir -p /root/.ssh  # -p makes it not do anything if the directory exists already
cp /mnt/BootDisk/authorized_keys2 /root/.ssh/
chmod 600 /root/.ssh/authorized_keys2

If you want to avoid repeating the path name, use a variable to abbreviate it.

p=/root/.ssh
a=authorized_keys2
mkdir -p "$p"
cp /mnt/BootDisk/"$a" "$p"/
chmod 600 "$p"/"$a"

This way, it's also easier to globally replace the path name if you ever want to do that -- only one place to change.

PS. Since this question is by and large unrelated to your original question,. perhaps you should have started a new thread.

Yes, your right, prob should have startd a new thread.

I see what you mean when you said:

You don't need to cd to a directory -- any file-oriented command will accept a full path name just as well as a plain file name.

At first I was wondering; "If you do not use cd to move into a dir, how did you move into that directory."

If I understand correctly I think what you are saying is that,you don't need to go into that directory to create a new directory inside it, just use the complete path.

I had just started to read a bit about variables, and seen basic use in the tutorial I have been trying to work through....but until I get sh rather than csh, I am still a bit stuck.

Later today, I will downgrade my test box to the older 0.69b4 as suggested by Dan, and I should be able to learn a bit more.

Up until two weeks ago, I had not even looked at doing anything via the command line since I was at school 20 years ago, so learning a lot at the moment.

Thanks for the help

Neil

Just tried your edit of that script and could not get it to work. Was going to leave it till later, but could not leave it alone.
I was just getting a permission denied message.

Tried again typing it in manually rather than cut and paste from here on the forum, and it worked this time. I removed the comment line and it seemed happier and worked