Simple shell script issue

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

Similar Messages

  • Running a simple shell script

    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.
    Bill

    If 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 1

    spoonman 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"

  • 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

  • SQL LOADER and SHELL SCRIPT ISSUE

    Hello Guys,
    I know this not the right forum but i am not sure where i should post this.
    Pelase help
    I am running a shell script which is giving me error
    Username:SQL*Loader-128: unable to begin a session
    ORA-01017: invalid username/password; logon denied
    SQL*Loader: Release 10.2.0.4.0 - Production on Thu Nov 19 13:02:04 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Nov 19 13:02:06 2009
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Enter user-name:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>
    0 rows updated.
    Commit complete.
    SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition
    SQL> SQL> Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options Thu Nov 19 13:02:06 EST 2009In shell script i have used the same username and passwd which i am using from command line
    the shell script is calling sql loader to load file
    and for that also the username and passwd is same.
    i am able to run sqlldr command from command line dont knw why here its giving error
    here is my shell script
    set -a
    . $HOME/.edw.env
    . $admlib/checklib.sh
    LOGDIR=$admsrc/sigma6/ppadala/copg
    LOGFILE=${LOGDIR}/log/test`date '+%m%d'`.xtr
    DB_USER=copg
    DB_PWD=copg
    set +a
    cd $LOGDIR
    if test ! -f $admsrc/sigma6/ppadala/copg/DM_Daily_EFolderCloseCancel_Report_11192009.txt
    then
       echo "Error: DM_Daily_EFolderCloseCancel_Report_11192009.txt does not exist and/or is not a regular file." >> ${LOGFILE}
       exit 1
    fi
    echo 'End of Checking for the existence of the file - Successful'>> ${LOGFILE}
    sqlldr control=$admsrc/sigma6/ppadala/copg/Close_Cancle.ctl log=$admsrc/sigma6/ppadala/copg/Close_cancle.log
    userid=${DB_USER}/${DB_PWD} silent=\(HEADER,FEEDBACK,DISCARDS\)>> ${LOGFILE} 2>&1
    case $? in 0) :;;1|3) echo "Error: SQL Loader" >> ${LOGFILE}
         exit 1;;
    esac
    sqlplus << EOD
    ${DB_USER}/${DB_PWD}
    @Close_Cancle.sql
    EOD
    if [ $? -ne 0 ]
    then
        echo "Error: SQL Plus for script Processing" >> ${LOGFILE}
        echo "Resi Unit Scheduling Report Refresh failed" >> ${LOGFILE}
    fi
    ) > ${LOGFILE} 2>&1
    echo `date` >> ${LOGFILE}
    if [ -f ${LOGFILE} ]
    then
    mail -s "Resi Unit Scheduling" "[email protected]" < ${LOGFILE}
    sleep 3
    `ck_error ${LOGFILE}`
    fiplease help guys
    thanks

    Thanks for the reply
    In Close_cancle.log also its the same msg which i posted.
    logon denied..............
    and this is the log file contents when i do set - X on
    + cd /u2144009/src/sigma6/ppadala/copg
    + test ! -f
    + /u2144009/src/sigma6/ppadala/copg/DM_Daily_EFolderCloseCancel_Report_1
    + 1192009.txt echo End of Checking for the existence of the file -
    + Successful
    + 1>> /u2144009/src/sigma6/ppadala/copg/log/test1119.xtr
    + sqlldr control=/u2144009/src/sigma6/ppadala/copg/Close_Cancle.ctl
    + log=/u2144009/src/sigma6/ppadala/copg/Close_cancle.log
    Username:SQL*Loader-128: unable to begin a session
    ORA-01017: invalid username/password; logon denied
    SQL*Loader: Release 10.2.0.4.0 - Production on Thu Nov 19 17:32:17 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    + userid=copg/copg silent=(HEADER,FEEDBACK,DISCARDS)
    + 1>> /u2144009/src/sigma6/ppadala/copg/log/test1119.xtr 2>& 1
    + :
    + sqlplus
    + 0<<
    copg/copg
    @Close_Cancle.sql
    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Nov 19 17:32:58 2009
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Enter user-name:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>
    0 rows updated.
    Commit complete.
    SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition
    SQL> SQL> Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    + [ 0 -ne 0 ]
    Thu Nov 19 17:32:59 EST 2009Edited by: user10647455 on Nov 19, 2009 2:35 PM

  • 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 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
    done

    Re-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 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.

  • 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. ;)

  • Shell script issues in yosemite - they run on previous OSX versions

    Hi,
    I've recently bought a new MacBook and I've got my old one with me as well. I am a Java developer running my applications on Tomcat 7.0.47 running on Mountain Lion on my old laptop. The same tomcat when copied to my new laptop does not work. When I try to start the catalina.sh script, it gives me the following error
    ./catalina.sh: line 534: syntax error near unexpected token `('
    ./catalina.sh: line 534: `  echo "Usage: catalina.sh ( commands ... )"'
    Not sure what does this mean and how can I fix it? Was it a mistake to upgrade my new laptop to Yosemite?
    Please help.

    I can't solve this for you - I don't have the in-depth knowledge...
    But, I'm willing to bet this is due to the new security features of Yosemite - primarily what is called sandboxing.
    Some reading:
    https://developer.apple.com/library/mac/technotes/tn2206/_index.html
    About the security content of OS X Yosemite v10.10 - Apple Support
    https://threatpost.com/major-bash-vulnerability-affects-linux-unix-mac-os-x/1085 21

  • [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)

  • Shell script issue

    Hi All,
    Am new to DB and unix....Trying to find the diskspace utilization of the filesystem so as to get an alert if it crosses limit.
    Here is the code that i am trying to run but it doesn't seem to work. Need ur help on this
    #!/bin/bash
    #--To send a mail alert if the filesystem disk space is more than warning or critical limit--#
    warning=85
    high=90
    i=`df -k |sed '1d'| awk '{print $7 }'`
    while read $i
    do
    s=`df -k | awk '{ print $4}'|cut -d'%' -f1`
    if [ $s -ge $high ]
    then
    echo "URGENT: limit for $7 is crossed"
    break
    fi
    if [ $s -ge $warning ]
    then
    echo "WARNING: Low disk space for $7"
    fi
    done
    Error that i get is as follows
    + read / /usr /var /tmp ......
    d.sh[8]: /: This is not an identifier.

    Hi
    This will give you free space:
    free_space=`df -m | grep "/orashare" | awk '{print $4}'`
    Then to test:
    if [ ${free_space} -lt $space_free_threshold ]; then...
    To avoid getting multiple alerts, you may want to create a temporary file the first time the threshold has been reached, and then not send another message until the space problem has been resolved. At that stage remove the temp file again...
    Sorry - didn't read your whole post - oops. Looks like you're getting the error because of extra spaces between directories:
    /usr /var /tmp
    Should work once you remove these...
    Cheers,
    A.
    Edited by: Andreas Hess on Nov 24, 2009 2:13 PM

  • 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 " }"
    done

    No 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

  • Un-mounting larger memory drives

    Hi, I have a 16 GB memory USB drive, I drag this one in the trash to unmount, I can remove the drive without any warnings, but the drive image stays on the desktop, the next time I insert the drive it can not read it, I need to reboot the Mac. Tried

  • SRM Business Package built on Webdynpro java or webdynpro ABAP

    Hi Any can please clarify. Like ESS/MSS  and MDM business packages are built on java webdynpro, But  SRM Business packages are built on which technology like java webdynpro or ABAP webdynpro?  Please clarify it. Also clarify following questions? How

  • Closed captions unreliable in Captivate 6.0.1

    Hi all, The company I work for is getting ready for several courses to go live on their website. Accessibility, in the form of closed captioning, is very important to my employer and to our clients. We've put a lot of time into getting the captions t

  • MIGO Screen settings

    In MIGO From the menu setting there is one option of selecting copying Rule Transfer posting... Where exactly we use this..and how to use this option

  • HP Application LifeCycle Management - URL for use with another Project Management Tool

    I'm trying to find a way to get a ALM Requirement URL that will work with other applications.  The URL from the COPY URL option (when right-clicking on the requirement) works for e-mails but I can't seem to get it to work for another project manageme