How to automatically execute a command inside a certain file

Forum rules
Before you post please read this

How to automatically execute a command inside a certain file

Postby xskyjackerx on Fri Jan 06, 2012 10:25 pm

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
Image
User avatar
xskyjackerx
Level 1
Level 1
 
Posts: 3
Joined: Fri Jan 06, 2012 9:56 pm

Linux Mint is funded by ads and donations.
 

Re: How to automatically execute a command inside a certain

Postby Garvan on Sat Jan 07, 2012 1:38 am

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
Desktop: Dell, Intel Core 2 Duo E7500 @ 2.93Ghz, 2GiB RAM, Linux Mint 13 Maya.
Net-book: SAMSUNG N148-Plus, 2x Intel Atom CPU N450 @1.66Ghz, 1GB RAM, lubuntu 12.04.
User avatar
Garvan
Level 4
Level 4
 
Posts: 273
Joined: Sun May 29, 2011 3:26 am
Location: Cambodia

Re: How to automatically execute a command inside a certain

Postby mph426 on Mon Jan 09, 2012 9:23 pm

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
I'd rather have a bottle in front of me than a frontal lobotomy.
mph426
Level 1
Level 1
 
Posts: 23
Joined: Fri Dec 16, 2011 3:03 pm
Location: State of confusion

Re: How to automatically execute a command inside a certain

Postby Garvan on Tue Jan 10, 2012 2:11 am

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
Desktop: Dell, Intel Core 2 Duo E7500 @ 2.93Ghz, 2GiB RAM, Linux Mint 13 Maya.
Net-book: SAMSUNG N148-Plus, 2x Intel Atom CPU N450 @1.66Ghz, 1GB RAM, lubuntu 12.04.
User avatar
Garvan
Level 4
Level 4
 
Posts: 273
Joined: Sun May 29, 2011 3:26 am
Location: Cambodia

Re: How to automatically execute a command inside a certain

Postby xskyjackerx on Wed Jan 11, 2012 11:05 pm

Thank you so much guys.Im getting better with bash syntax now. :P
Image
User avatar
xskyjackerx
Level 1
Level 1
 
Posts: 3
Joined: Fri Jan 06, 2012 9:56 pm


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 3 guests