Page 1 of 1

How to automatically execute a command inside a certain file

Posted: Fri Jan 06, 2012 10:25 pm
by xskyjackerx
I am writing a script called First_Script,and i put it in my Scripting folder.I will continue to put my Scripts in the Scripting folder.I want to be able to just us this command line "First_Script"(or whatever the script name is.) and run the script.However right now i use ./First_Script.I would like to just type the designated directory in the ".profile" file were the script will be.So i dont have to type ./ every time(its annoying not hard).

Kinda like this... Image

However my .profile file looks like...
Image
So were do i put the command "export PATH=$PATH:directory"(Scripting)in the .profile file.

(I only want it to look in this directory for scripts)
Thanks

Re: How to automatically execute a command inside a certain

Posted: Sat Jan 07, 2012 1:38 am
by Garvan
Put it on the last line. I think it needs to be in quotes, and you need to show where the script folder is. For example I tried this and it worked.

export PATH="$PATH:$HOME/script"

I do not know if export is required. You can try with and without.

Garvan

Re: How to automatically execute a command inside a certain

Posted: Mon Jan 09, 2012 9:23 pm
by mph426
If you do, or want to do a lot of command line stuff, you may want to consider a few more variables.

Here's my .bash_profile.

Code: Select all

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi

# User specific environment and startup programs

LS_OPTIONS='--color'
PATH=$PATH:$HOME/bin
TERM=xterm
LESS=MMr

set -o vi 

export PATH LS_OPTIONS TERM LESS EDITOR

alias ll='ls -lh $LS_OPTIONS'
alias llm='ls -alh  $LS_OPTIONS| less'
alias lrt='ls -alhrt $LS_OPTIONS'
alias ls='ls  $LS_OPTIONS'
alias lsd='ls -lhd */ 2>/dev/null  $LS_OPTIONS'
alias lsnd='ls -lh  |grep -v ^d  $LS_OPTIONS'
alias cp="cp"
alias mv="mv"
alias df="df -h"
 
As you can see the variables are set individually, then exported on a single line. Exporting variables makes them global. That is to say that other instances of the shell can see them.
Oh yea, make sure to read the man pages for the terminal you want use. Usually a -ls will make it a login session and read the .bash_profile in. Most support it in one form or another.

I use ksh by preference, but I tested this with bash and everything should work fine.

HTH

Re: How to automatically execute a command inside a certain

Posted: Tue Jan 10, 2012 2:11 am
by Garvan
I have a few questions on the syntax mph426 may be able to help with.

In the original .profile posted by xskyjackerx the modified PATH variable is not exported, yet this is the default script, and it appears to work. Is export needed?

Also I do not understand this:

alias cp="cp"
alias mv="mv"

What does alias do in this case? And again, what is the scope of these changes.

Thanks, Garvan

Re: How to automatically execute a command inside a certain

Posted: Wed Jan 11, 2012 11:05 pm
by xskyjackerx
Thank you so much guys.Im getting better with bash syntax now. :P