Simple Shell Script To Add To Default Path?
I know that this question will at first appear idiotic,but here goes.
I'm logged into a Solaris 9 shell as 'root'. I echo $PATH and see a couple of default paths. I want to add to that PATH - this can easily be done from the command line as follows:
PATH=$PATH:/some/other/path
export PATH
So, naturally, I'd like to throw this into a simple script, and when I do so, and run the script called 'hello'. So, I run 'hello' as follows:
ksh hello (I'm a kshell)
Result: no errors. Then, I check my PATH as follows:
echo $PATH
And nothing changes, it's still the same PATH!
Can anyone tell me how to do this?
Appreciate your response.
dedham_ma_man
The question shows you don't really understand how shells work.
The path is part of the environment of your current shell.
Any command you "execute" is run in a new process. And any changes made to the environment of that process cannot effect the environment of the parent process (ie your shell).
So by saying "ksh hello" your starting a new shell and changing the path in that shell. But when that shells exits and your back in the original shell, of course nothing has changed.
So the answer is that what you have to do is not "run" the script. But persuade your current shell to execute in its own context.
In a C shell that would be done by the "source" command. And in a bourne shell, its the "." command. But I'm not sure how you do it in korn shell.
Similar Messages
-
Not being a regular user of terminal on OSX, I have managed to forget how to run a simple shell script. The purpose of the script is to rename a set of files contained in a specific directory. Here is a sample of the script I wrote some time back:
mv product_22.jpg 080688614423.jpg
This command repeats for each file I need to rename. My recollection is that I simply put the actual script text file in the same directory as the images to be renamed and drag the script file into a new terminal window and hit enter to run. When I try this however I receive the following error:
ord2: Permission denied
Can anyone help me out here? I'm running 10.2.8. I seem to beforgetting a critical step somewhere along the way.
Thanks
Mac OS X (10.2.x)Have you set the execution bit for the script? When not, use: chmod 755 script.
-
Creating simple shell script packages to deploy with ARD and TaskServer
I am looking for a simple step by step on how to create a package that can be deployed using ARD, to run a simple shell script like
"softwareupdate -i -a"
A brief search here returned nothing, but perhaps I was not using the correct terms.
Ultimately, I want to use ARD to run software update on ~400 Macs.
Thanks in advance for your help.
BillIf I send it as a unix command, it will run only on machines that are currently awake and responding to ARD.
If I can set it up as a package, then I can use Task Server to "deploy" the command to machines that are not currently online. When the machines next contact the Task Server, they will be told to run softwareupdate. -
Simple shell script utility to copy abs tree for build
Hi,
I'm learning shell script and decided to make a simple script to copy the folder i want from /var/abs to
a new folder so i can build the package. here it is: (remember, i'm new to shell scripting, if you know a better way to do it, you can modify my script
and post here a better solution, so, i (and others) can learn with my errors)
#!/bin/bash
#Looks for the abs tree of the software you want
#and copy it to your build path
ABSTREE=/var/abs
echo -n "What software do you want? "
read absname
result=$(find $ABSTREE -name $absname)
for i in $result; do
echo -n "$i, is this what you want? [y/n] "
read opt
if [ $opt = "y" ]; then
echo -n "Copy to... "
read buildpath
relative=${i#$ABSTREE}
absolute=$buildpath${relative%$absname}
mkdir -p $absolute
cp -r $i $absolute
echo "$i successfully copied to $absolute"
exit 0
fi
done
exit 1spoonman wrote: mkdir -p $absolute
cp -r $i $absolute
echo "$i successfully copied to $absolute"
You are assuming `mkdir` and `cp` were successful. You should test them to make sure, and exit with failure if not:
mkdir -p $absolute || exit 1
cp -r $i $absolute || exit 1
echo "$i successfully copied to $absolute"
You could also include your own error message, but mkdir and cp would throw their own if something fails...
mkdir -p $absolute || { echo "mkdir failed"; exit 1; }
cp -r $i $absolute || { echo "cp failed"; exit 1; }
echo "$i successfully copied to $absolute"
Another way is to use `set -e` which will exit the script on any failure without explicit testing:
set -e
mkdir -p $absolute
cp -r $i $absolute
set +e
echo "$i successfully copied to $absolute" -
Hi,
I am trying to launch Amazon EC2 windows server 2008 R2 instance using AWS Auto Scaling feature. I have used cusmized AMI in Autoscaling Launch configuration to launch an instance.I have placed Power Shell script in AMI.
The responsibility of script is to download code from AWS S3 and deploy in IIS server while windows startup first time.
When i check status, IIS is started succesfully. But default Application pool is not started.
To resolve this issue i have written one scheduled script. It helps to start the application pool if any application pool is in stopped state.
After this Application pool is started but i am not able to communicate with IIS server through browser.
Please help any one to resolve this issue.
Thanks in advanceHi Vchreddy,
For the IIS issue, we recommend you can post in IIS forum for more effective support:
http://forums.iis.net/
Thanks for your understanding. -
How to use the result of simple shell script?
The shell script below retrieves the length of an audio file:
set aFile to choose file
do shell script "afinfo " & quoted form of (POSIX path of aFile) & "|grep duration"
I'm wondering, how can I copy the result to the clipboard or set the value of a variable to it?
Total newbie question. I have no idea about shell scripts - I just found the script above online.
Thank you so much!Here:
set the clipboard to (do shell script "afinfo " & quoted form of (POSIX path of aFile) & "|grep duration")
or:
set A to do shell script "afinfo " & quoted form of (POSIX path of aFile) & "|grep duration"
(53997) -
Simple Shell Script Question.... [java related]
Hey guys! This is my first post, as im new here :S
I have a simple problem for a big program.
We have a .sh to install it, but when I run the .sh in terminal like i should, It says the class is not found. I believe it has to do with the syntax, as the person who made it is not a linux pro. I don't know MUCH about shell scripts, but I'm pretty sure I know where the error lies.
Our Script:
java -classpath ./:./jars/tools.jar:./jars/nexus.jar impsoft.nexus.installer.Install
chmod a+x run.sh compile.sh
The Error:
Exception in thread "main" java.lang.NoClassDefFoundError: impsoft/nexus/installer/Install
What I think the problem is:
./jars/nexus.jar impsoft.nexus.installer.Install
Thank you for ALL of your help!Hi Justin,
Have you tried running the lines from the command line?
The second thing you may want to try is changing the relative directory for the jar file from a relative one to a fixed directory. From the error, it appears that the install program is running but it is not able to locate a library mentioned in the program (which is probably the jar file listed in the classpath).
Hope that helps.
J. Haynes
Denver -
Simple bash script to add a '-' [Solved]
I need to write a small bash script to add a '-' to each line in a file before displaying via conky!
Todo
- Get Milk
- Buy Food
- Pay Bills
Currently I use
TEXT
Todo
${hr}
${head /home/mrgreen/.stuffigottado.txt 30 20}
In .conkyrc but have to add '-' each time I edit .stuffigottado.txt
Thanks in advance....Cerebral wrote:
To filter out blank lines, you could just modify the awk command:
${exec awk '!/^$/ { print "-", $_ }' stuffigottado.txt}
very nice; awk and grep: two commands that never cease to amaze me. -
Hi,
I have an issue with following shell script:
#!/bin/sh
env | while read VAR; do
RIGA=$RIGA"\""$VAR"\";"
done
echo $VAR
echo $RIGA
exit 0
Why the last echo commands (echo $VAR and echo $RIGA) don't give me any result? Why $VAR and $RIGA are empty?From what I understand, anything to the right of a pipe is run in a sub-process in non POSIX shells, which runs in it's own environment. Variables changed inside ta sub-shell are not changed at the parent process.
Perhaps using ksh instead of bourne shell will work, or you could try input redirection rather than using pipe command. e.g.:
while read VAR; do
RIGA=$RIGA"\""$VAR"\";"
done < $(env)
echo $VAR
echo $RIGA
exit 0
Edited by: Dude on Dec 15, 2010 6:11 AM -
Simple shell script problem...
I am trying to get a list of directories on a remote machine, compare them with the directories on the local machine and copy any that dont match on the local machine to a backup folder. Heres my code but i am a newbie and i cant get my shell script to read from a file. The for loop never executes so i am guessing i am not reading the file correctly - see below.
#!/bin/ksh
ssh -l removeserver 192.168.xxx.xxx ls /remote/server/directory/ > /store/remote/directory/listing/motapp1files.txt
newfile=''
$newfile < /store/remote/directory/listing/motapp1files.txt
for file in $newfile;
do echo $file
if [ ! -d local/machine/directories/$file/ ]; then
echo "this folder doesnt exist on on remote server "; echo $file;
fi
doneRe-inventing the wheel perhaps. Look into rsync. Great program!
I used it in FreeBSD to do a very similar task. -
Create a simple shell script thing?
Hey,
I'm trying to make a simple command script thing. I have no idea what I'm doing though.
I just want a file that I can click and open in terminal that will:
1. ssh [email protected]
2. auto enter the password (if this is really complicated then it can be skipped)
3. cd public_html/blog
4. svn up
5. like 5 sec delayed exit (if possible)
I'm thinking this is a really easy thing to do for someone who knows what they're doing.
So can someone tell me what I have to do to make this? I would really like to learn how to do this.
Thank you
Last edited by FLCLFan (2008-10-12 20:06:20)Instead of making a script, you could just as well write a bash function for this and put it in your .bashrc.
something like this:
update-svn-on-domain ()
ssh -t [email protected] 'svn up public_html/blog'
when the svn up is done, the ssh command stops, and the function returns. it does everything you want except auto entering passwords.
i strongly discourage auto entering passwords. i recommend you to setup rsa key authentication -
Simple shell script to create linkedClones on stand alone ESXi host.
Hey Guys,
Last few days I have been working on creating linkedClones in bulk for some of the testing purpose. Since I did not had my vCenter up and running so I spend few minutes to write a simple script to create a linkClones on standalone ESX host.
My script create full clone of given VM, then creates snapshot on it and starts creating linkedClones from the delta vmdk files (it just create new directory for linkedClone VM's and copies those delta files to new location and then point it to base disk, nothing magic here ).
Now this script is working perfectly fine for me, and I can power on all the VM's which is pointing to base disk. Later I tried creating linkedClones using vCenter API's as well which seems to be doing the similar thing.
So I just want to check with you guys if my script is Ok or thats not the way to do it (this may be unsupported way of creating linkedClones but I just want a way to create linkedClones on standalone esxi host as I may not have vCenter server available everytime) ?Hi!
As long as your softsynths comes in the VSTi format (most of them do now), you can insert it on a track in Audition, which has 'host' capabilities from V3.
In the Multitrack, insert a new MIDI track from the 'Insert' menu (note: MIDI Track, not just 'MIDI').
On that track pane hit the 'Sequencer' button, and it will open in a separate window. In the pane left of the keyboard you can insert your VSTi of choice, and make your MIDI connections.
Back on the Main track pane, engage the 'L' button for Live monitoring. Actual recording (of MIDI) is done in the Sequencer window.
The usual, and recommended workflow is to keep the MIDI tracks 'open', i.e. you can edit the sound in your instrument and even the notes played at any time in the process, compiling the actual audio as the last step in the mixing.
If you kind of 'insist' on doing it the old way, you can export the audio from your recorded MIDI+VSTi creations track by track like this: Leave the Sequencer window open, make a selection in the multitrack that covers the time span you have played. Solo the track (will mute all others), and use File / Export Audio Mixdown. Use 'Master' as the source. This will give you a wave rendering of what's currently in the MIDI sequencer. Qualitywise this is better since it's all internal and digital instead of in/out of soundcards with DA/AD conversion etc.
I haven't found a method for a 'live' wave recording while you play, but there may be one...
If you purchase Audition it comes with Help files explaining this in more/better detail. ;) -
[SOLVED] Simple Shell Scripting Question - Echo and Execute?
I've got a bash script which has many different commands it executes in a row. Each time the script executes one of the commands, it outputs what it is doing to the screen:
echo "cp -r home new"
cp -r home new
echo "mv testfile new/."
mv testfile new/.
I am just wondering if there is a function to execute a command and output it at the same time. Something like...
echoandexecute("cp -r home new")
echoandexecute("mv testfile new/.")
Last edited by tony5429 (2008-08-27 19:59:04)Otherwise you can define it yourself:
echoandexecute() {
echo $1
$1
echoandexecute "cp -r home new"
Last edited by catwell (2008-08-27 20:57:16) -
Power shell script to add multiple aliases with a .csv file.
I have an email address lets say [email protected] and I need 1000 aliases added to the email. For example [email protected], [email protected] etc etc. and I have a .csv file with 990 columns with just project1, project2.
Is there a way to run a command in powershell exchange to import all the aliases I need in a few commands? Can someone point me in the right direction if I am in the wrong forum also? Thanks
No sure if this is correct or not:
> $mbx = Get-Mailbox Project
> Import-CSV "C:\SomePath\wherever.csv" | foreach { $mbx.EmailAddresses += $._SmtpAddress }
> Set-Mailbox project -EmailAddresses $mbx.EmailAddressesHelp Import-Csv -FULL
$aliases=Import-Csv aliases.csv
¯\_(ツ)_/¯ -
Simple Pekwm Categorized Menu Populator (Shell Script)
I wanted to share this script I wrote in the hope that it will prove to be as convenient to some of you as it has been to me.
Suggestions and modifications are welcome.
#! /bin/sh
#USING WITH PEKWM
# -Install this file to ~/.pekwm/scripts/menugen.sh
# -Add this line to ~/.pekwm/start:
# ~/.pekwm/scripts/menugen.sh > ~/.pekwm/dynamic
# -Add this line where desired to the RootMenu section of ~/.pekwm/menu:
# INCLUDE = "dynamic"
# -Reload Pekwm
# -Restart Pekwm
#This will allow the menu to regenerate each time Pekwm restarts.
#MAKING ADJUSTMENTS
#Select a list of categories into which you would like your applications to be sorted, then add them to the "CATS=..." line below separated by spaces.
#Some common values are:
# CATEGORY DESCRIPTION
# AudioVideo Application for presenting, creating, or processing multimedia (audio/video)
# Audio An audio application Desktop entry must include AudioVideo as well
# Video A video application Desktop entry must include AudioVideo as well
# Development An application for development
# Education Educational software
# Game A game
# Graphics Application for viewing, creating, or processing graphics
# Network Network application such as a web browser
# Office An office type application
# Science Scientific software
# Settings Settings applications Entries may appear in a separate menu or as part of a "Control Center"
# System System application, "System Tools" such as say a log viewer or network monitor
# Utility Small utility application, "Accessories"
#For a better idea of how your applications may be categorized, you may also want to inspect the contents of the "Categories=" line of the various *.desktop files under /usr/share/desktop/
CATS="Audio Graphics Network Settings System Utility"
for CAT in $CATS; do
echo " Submenu = \"$CAT\" {"
for CATMATCH in `grep -l "^Categories=.*$CAT.*" /usr/share/applications/*.desktop`; do
name=`sed -n '1,/^Name=/ s/^Name=//p' <$CATMATCH`
exec=`sed -n '1,/^Exec=/ s/^Exec=//p' <$CATMATCH`
echo " Entry = \"$name\" { Actions = \"Exec ${exec% %[UuFf]}\" }"
done
echo " }"
doneNo matter how you chose to do it it's going to be a bit more work than a simple shell script. There are a lot of choices though.
Objective-C/Cocoa (this is how most of the big boys do it)
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCTutorial/01Introdu ction/chapter1_section1.html
AppleScript Studio
http://developer.apple.com/documentation/applescript/conceptual/studiobuildingap ps/chapter01/chapter1_section1.html
Python/Cocoa bridge
http://developer.apple.com/cocoa/pyobjc.html
There are more options if none of these appeal to you.
Eric
Maybe you are looking for
-
Why do I keep getting an error message from Digital Editions saying that it has encountered a problem and needs to close. I need this programme to download a text book from Proquest for University work what gives????
-
Trying to get a billing issue resolved, getting no...
I have been been going around in circles with BT. It all started about a month ago when we recieved a call from BT saying that if we didn't pay our bill, we'd be cut off. We hadn't received a bill, it must have never been sent, or been lost in the po
-
Cannot connect to YouTube or safari
My son iTouch for some reason refused to connect to YouTube and safari . Error was "cannot connect tou you tube" and on safari just spins but never connect. Odd the apppear tobe copnnect to my wireless Hub ok. Follow most of the solution but none wor
-
Validation function, PL/SQL is not being executed
Hello there, In one of my APEX listener setups I want to give access to only one application and block the rest. Basically I am following this nice post from Kris Rice: http://krisrice.blogspot.com.ar/2013/01/apex-listener-plsql-validations.html My p
-
Regarding changing the application settings for Financial management (BPM)
Hi, I have built the sample Comma application in HFM 9.3.1 using the BPM functionality from workspace as outlined in the documentation. The consolidation rules are set to "N" for this application when I open the XML using the window client. Can anyon