Will not work on execute...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Will not work on execute...
# 1  
Old 09-08-2008
Data Will not work on execute...

I am 100% new to Unix and trying to learn.
This is my first time even touching a script in Unix.

We have the following variable script that I am trying to run....

Code:
##################################
###### variable test###
##################################
Hostname=`hostname`
export PS1='${Hostname}:${PWD}>'
OMNIHOME=/lcl/prd/apps/Tivoli/netcool/omnibus
export OMNIHOME
NCHOME=/lcl/prd/apps/Tivoli/netcool
export NCHOME
NETCOOL_LICENSE_FILE=27000@seville
export NETCOOL_LICENSE_FILE
JAVA_HOME=/usr/java
export JAVA_HOME
PATH=$PATH:$NCHOME/omnibus/bin
export PATH
LD_LIBRARY_PATH=$NCHOME/platform/solaris2/lib; export LD_LIBRARY_PATH
NC_RULES_HOME=$NCHOME/common/rules; export NC_RULES_HOME
stty erase ^H
EDITOR=vi

Now if I try to excute this by the following....
./logintest.sh

It just goes right back to a bash-3.00$ prompt and does nothing.

If I try it this way....

sh logintest.sh I get this....

logintest.sh: PS1=${Hostname}:${PWD}>: is not an identifier


Now if I do a more on this file and then do a highlight with a right click to place the commands directly in then it works just fine. Also the perms are set to 777.


Could anybody please tell me what I am doing wrong? I am really lost here.

Thanks in advance!
# 2  
Old 09-08-2008
Consider adding your script to the .bashrc file so you do not have to source your script to make those changes happen to your envrionment
Code:
# two ways to source 
source myscript.sh
# or  (note the leading dot  - space )
.  myscript.h

# 3  
Old 09-08-2008
So I guess I still do not understand though.... Why is the above not working for me when I execute the sh file?
# 4  
Old 09-08-2008
Can something like this...
export PS1='${Hostname}:${PWD}>'

Only be used in a .profile in Unix?
# 5  
Old 09-08-2008
ok.

when you write a script, then execute it, the script runs as a child process. Any changes you make to the environment (variables are part of the environment) are made to the child's envrionment. When the child exits at the end of the script, you revert back to the parent environment. All child changes are lost.

<dot space>script.sh - means runs this in the parent envrionment. This is called sourcing. bash supports a builtin function, source, which is the same as the dot thing.
When you source some script, environment changes are kept in the same process, the parent. .bashrc or .profile are run when you login - they are sourced.
# 6  
Old 09-08-2008
Ok so what your saying is that this indeed running expect that after the run because its a child its going back to before the run so fast that it looks as if it never ran? I think I got that right.
# 7  
Old 09-08-2008
No. Parent has memory with variables in it. Child inherits new copy of memory with identical memory. Child changes memory. Child exits. Child memory ceases to exist. Parent memory takes over again, but never, ever was changed. Parent cannot know about child changes.

It has nothing to do with going by fast.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script without execute permissions will work for a user?

Please help me to understand the issue: Issue: There are shell scripts in a user home directory (/home/user_1) without execute permissions (rw-r--r--) to owner,group and world These shell scripts were able to execute/work previously but its not working now and it says permission denied or... (2 Replies)
Discussion started by: MSK_1990
2 Replies

2. IP Networking

Discussion at work, would a router work pluging a cable in wan1 and lan1?

hi all. and sorry for the random question, but this sparkled a raging flame-war at work and i want more points of view situation a router, with linux of some sort, dhcp client requesting for ip in wan1 (as usual with wan ports) dhcp server listening in lan1, and assigning ip (as usual... (9 Replies)
Discussion started by: broli
9 Replies

3. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

4. IP Networking

NIC will not work, but it did work.

I have a client machine that was built and loaded with SCO UNIX 2.1.3, (yes it is old). The machine worked fine on the closed network that I tested on in my shop. I then had to change it to the network that it would be connected to. Below is the host file, router and subnet mask file that I usually... (0 Replies)
Discussion started by: NC user
0 Replies

5. Shell Programming and Scripting

execute

can someone tell me what is the difference between . and ./ in a script (3 Replies)
Discussion started by: TimHortons
3 Replies

6. Shell Programming and Scripting

execute c

i wish to have a shell script which receives the file name and path (from the user) to a text file that contains a c program and compiles the program code using gcc and displays the execution of the compiled file (which is saved as filename.c) in the terminal / konsole Can any one help me by... (1 Reply)
Discussion started by: anurag.mishra1
1 Replies

7. Shell Programming and Scripting

execute

Hi All I have a file containing the following information SOURCESERVER DESTINATIONSERVER DESTINATIONENVIRONMENT CONDITION I was trying to read and then execute the conditions,like if SOURCESERVER is XXXX0001 and the DESTINATIONSERVER is XXXX0002 and the DESTINATIONENV is YYY the... (3 Replies)
Discussion started by: bkan77
3 Replies

8. Shell Programming and Scripting

script execute or no execute

o hola.. Tengo un script que se ejecuta bajo una tarea del CronJOb del unix, tengo la version 11 de unix, mi script tiene un ciclo que lee unos archivos .txt luego cada uno de esos archivos debe pasar por un procedimiento almacenado el cual lo tengo almacenado en mi base de datos oracle 10g,... (4 Replies)
Discussion started by: Kespinoza97
4 Replies

9. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

10. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies
Login or Register to Ask a Question