Hello All,

I am new to linux and I m trying to build a series of startup scripts. My goal is to call one startup script that then calls several others based on conditions. I am starting with a simple alias script. I have read many posts on this and I feel I am very close but I missing something. The main way I have focused on is using run levels. I should also mention that I am running BT4.

I created a file in the init.d directory called callStartup. I added the neccessary permissions for it to be executable (chmod +x /etc/init.d/callStartup)

I then ran #sudo update-rc.d /etc/init.d/callStartup start 99 2 3 4 5 .

I was able to confirm that a link was placed in the appropriate run level directories.

in callStartup, I only have two lines:

source /custom/scripts/startup/startup;
echo 'Custom Files Loaded';

I have also tried the following for the first line:

sudo sh /custom/scripts/startup/startup.sh;
sudo sh /custom/scripts/startup/startup.sh;
sh /custom/scripts/startup/startup.sh;

In the startup file, I have one line:

source /custom/alias/custom_alias;

In the custom_alias, I have the following:

alias connect="sudo iwconfig eth1 {appropriate network config}";
alias turnOff="sudo shutdown now;";
alias restart="sudo shutdown -r now;";

When I first boot bt4, before I start the GUI (command startx); before the login prompt I see the message from the callStartup file: Custom Files Loaded. However, when I do alias, none of my custom aliases show. If I do either of the following in the terminal it works fine:

source /custom/scripts/start/startup;
source /custom/scripts/alias/custom_alias;

I would appreciate any advice on what I am doing wrong. Thanks.

You aliases are probably not being exported to the calling shell.
When you call
sh /custom/scripts/startup/startup.sh;
your aliases are probably available within the new instance of the sh shell.
I think you have to export your definitions to make them available in calling shell.

Every time you execute a shell, it starts with default settings and runs some scripts to customize itself to make whatever aliases you defined available. Thats why, in most cases, aliases are placed into scripts that shell executes every time it starts. This is usually files like .bashrc or .bash_profile in your home directory. If you define your aliases there, they should always be available.

Sourcing the files should take care of that, but what you may want to do is put a little more debug output in your script.

"source" isn't a command, it's a bash command, so make sure that all of your startup scripts are calling #!/bin/bash or where ever it is installed.

Once you source a file, try to run the aliases command to output so you have an idea if it loaded correctly.

#!/bin/bash

source /custom/alias/custom_alias;
alias

Even though /bin/sh is sometimes a symlink to /bin/bash (this may be a RH only thing, not entirely sure), it behaves like the shell it's called as, so it's very possible that /bin/sh doesn't source the same as bash may.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.