Sponsored Content
Top Forums Shell Programming and Scripting Guidance required in .profile Post 303037340 by apmcd47 on Tuesday 30th of July 2019 04:39:18 AM
Old 07-30-2019
Quote:
Originally Posted by cokedude
Not every server I use has bash so I wanted to add an option to check if bash exists. This is what I tried. This is the error message it gives "-bash: [: missing `]'". It works before I add the and option.

Code:
if [ -s ~/.bashrc && -s /usr/bin/bash ]; then
    echo hi
    source ~/.bashrc;
fi

The problem with the above is, if bash exists but you are not running bash, your shell will baulk at an instruction in the .bashrc file.

Try something like this at the end of your .profile:
Code:
if [ -z "$BASH_VERSION" ] 
then
   if [ -x /usr/bin/bash ]
   then
      SHELL=/usr/bin/bash
      export SHELL
      exec $SHELL
   elif [ -x /bin/bash ]
   then
      SHELL=/bin/bash
      export SHELL
      exec $SHELL
   fi
fi

This way, if bash exists, but is not your login shell, your shell will switch to bash at the end of the .profile. You can also add a test for bash being in /usr/local/bin.

Andrew
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

changed .profile but didnt ./.profile, yet reflected changes

hi , i added ls -F to .profile. and i need to do ./.profile for the effect to take effect BUT i didnt and YET the next day when i came to work and log in, the changes took effect. i am on aix. please explain.. thanks (4 Replies)
Discussion started by: yls177
4 Replies

2. AIX

NIM Guidance

I've just started to explore NIM and I'm looking for additional information on how to set it up and configure it. I've read through the "NIM A-Z" and have many unanswered questions. One question is how can I have the NIM server pull a mksysb of the clients and can I schedule this to happen... (1 Reply)
Discussion started by: scottsl
1 Replies

3. What is on Your Mind?

Career Guidance

Hi, I am a newbie to Unix, I was introduced to UNIX 8 months back during my Training, I was attracted to Unix as they give complete freedom. I would like to ask how can a OS Admin can go into development field of Unix. Currently I am working in a MNC in Backup- Storage Admin Domain I am... (1 Reply)
Discussion started by: sufi_431
1 Replies

4. Shell Programming and Scripting

A little guidance needed :)

Hi guys, I'm learning the ropes of BASH and am doing a few exercises to see if its sinking in but have gotten stuck on something I KNOW is looking at me right in the face but just isn't registering. I'm creating a script that needs to get specific strings from a line. So using the "ls -l... (9 Replies)
Discussion started by: shadow0001
9 Replies

5. Infrastructure Monitoring

trap in etc/profile and user .profile

Hello I really wonder what's trap in etc/profile and in each user .profile. I try to google for it but I think I have no luck. Mostly hit is SNMP traps which I think it is not the same thing. I want to know ... 1. What's a "trap 2 3" means and are there any other value I can set... (4 Replies)
Discussion started by: Smith
4 Replies

6. Shell Programming and Scripting

guidance required: feed load search & display in shell scripting

Hi All, I am fairly new to Shell Scripting, however learning fast ;-) I have been asked to do the below basic shell script :confused: There are few feed files we are recieving in the server from multiple locations spread out during the day, rite now we are checking manually each file... (2 Replies)
Discussion started by: sachaan
2 Replies

7. AIX

Need guidance on VMStat

I need some guidance on the differences in observations, not sure how significantly different are they. Also, It would be nice to hear on the values and what the obvious tuning for performance missing. Observation 1 ending vmstat -v 3948544 memory pages ending vmstat -v ... (1 Reply)
Discussion started by: Snipper
1 Replies

8. UNIX for Dummies Questions & Answers

Just need some guidance on this nawk

Hi, I am trying to debug some KSH script and it has the nawk portion below. I just want to confirm whether I understand what it does correctly. Example usage of the nawk line is run as below: nawk '/^#/ {next} $1~/^'testp.cfg'$|^'testp.cfg'\.testdb\.com\.ph$/ { c=0 while... (1 Reply)
Discussion started by: newbie_01
1 Replies

9. Shell Programming and Scripting

Need Some guidance on scripting

Hey All, I am newbie on scripting and need some guidance from all the experts here. I am working on one project where I will check the status/health of around ten (10) solaris 10 servers. I have one central server from where I have already setup the passwordless SFTP and setup the cron... (1 Reply)
Discussion started by: supercops
1 Replies

10. AIX

New to AIX. Need Guidance

Hi There, I am new to AIX. I am eager to learn the AIX System administration or if there is any other prerequisite before this. Please can anyone help me or guide how to start with AIX, what all courses and certifications do I need to do. I have basic knowledge of UNIX. Please guide as I am... (3 Replies)
Discussion started by: rahulat302
3 Replies
COMMAND-NOT-FOUND(1)					    http://en.opensuse.org/Sco					      COMMAND-NOT-FOUND(1)

NAME
command-not-found - A command-not-found handler SYNOPSIS
command-not-found {binary_name} {repository} ARGUMENTS
The following arguments are required: binary_name The name of binary you are looking for. repository The name of repository for search. For most cases, use zypp DESCRIPTION
command-not-found handler is designed to tell users which package contains a missing command. The handler is integrated to bash(1) and zsh(1) shells and is not necessary to call it directly. Just type a name of the command in your favourite shell and you'll get a result. If you consider c-n-f handler useless, just add unset command_not_found_handle to your profile or remove the command-not-found package. Handler doesn't call the command-not-found binary directly, it only prints info about it. If you want to invoke it automatically, just add export COMMAND_NOT_FOUND_AUTO=1 to your bash profile. EXAMPLE
: NORMAL USAGE For example you want to try blender, because you have heard that is an amazing program. So just type blender in shell: $ blender You get the following output: The program 'blender' can be found in the following package: * blender [ path: /usr/bin/blender, repository: zypp (openSUSE 11.1-0) ] Try installing with: sudo zypper install blender bash: blender: command not found SEE ALSO
scout(1) AUTHOR
Pavol Rusnak <stick@gk2.sk> Developer http://gitorious.org/opensus 08/07/2009 COMMAND-NOT-FOUND(1)
All times are GMT -4. The time now is 05:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy