Shell scripting question

I'm writing a shell script and I need to get $PWD. There's a cd command in my script, and my script needs to navigate back to the directory in which it was executed. Is this possible? If so, how would I go about doing it? Sorry if this is in the wrong board.

In the future, you may want to post Unix and Terminal oriented questions to the Mac OS X Technologies > Unix Forum
<http://discussions.apple.com/forum.jspa?forumID=735>

Similar Messages

  • Shell script question

    Hi all,
    I know this is a little bit off subject but i have a shell scripting problem and was wondering if any of you could help...
    so:
    L=`wc -l $CATALINA_HOME/webapps/EmailSignup/Data/add.txt`
    stores the number of lines some file has...
    eg output:0 /usr/local/tomcat4/webapps/EmailSignup/Data/add.txt
    so now i want to have an if statement that will compare to see if the number of lines are equal to zero...
    how can i do that... this is what i do but it never seems to go in the if...
    it always goes in the else..
    if [ "$L" == " 0 /usr/local/tomcat4/webapps/EmailSignup/Data/add.txt" ] ;
    then
    echo $L
    echo No additions to the Email List
    else
    echo --$L
    echo Adding new entries to the Email List
    fi
    any ideas?
    thanks
    udam

    Try using the '-eq' operator of the 'test' program. (Square [] brackets in a Bourne shell script invoke the '/bin/test' program for your convenience. See the man page for 'test' for more info.)
    '-eq' compares two values NUMERICALLY, while '==' compares two values as STRINGS.
    Oops, I see what the other poster said about the leading space. What you really need to do is cut the number out of the string. You don't care about the file name.
    if [ `echo "$L" | cut -c 1-7` -eq 0 ] ;
    then
      echo $L
      echo No additions to the Email List
    else
      echo --$L
      echo Adding new entries to the Email List
    fi

  • Shell Script Question re: Cut Training Policy

    My shop uses KXEN version 5.1.3, and I've inherited an older shell script that defines the CutTrainingPolicy as "random". Here is a piece of the code:
    createModel Kxen.SimpleModel newmodel
    newmodel.getParameter ""
    newmodel.changeParameter Parameters/CutTrainingPolicy "random"
    newmodel.validateParameter
    newmodel.pushTransformInProtocol Default Kxen.RobustRegression
    newmodel.pushTransformInProtocol Default Kxen.ConsistentCoder
    newmodel.openNewStore Kxen.FileStore c:/temp
    newmodel.newDataSet Training train.txt
    etc.
    A user has requested that I test a custom cutting strategy without test, so I set it up in the GUI and exported the script. It now looks like:
    #GENERATED_BY_KXEN
    # KXEN Shell Script
    # generated on 2014-08-13 17:16:07
    # by KXEN version 5.1.3
    default STORE_USER ""
    default STORE_PWD ""
    default DESC_USER ""
    default DESC_PWD ""
    #Declaring the 'ESTIMATION' store and space
    default ESTIMATION_STORE_TYPE "Kxen.FileStore"
    default ESTIMATION_STORE_NAME "D:\DATA/199710"
    default ESTIMATION_STORE_USER $STORE_USER
    default ESTIMATION_STORE_PWD $STORE_PWD
    default ESTIMATION_STORE_ALIAS myEstimationStore
    default ESTIMATION_SPACE "model219.txt"
    #Declaring the 'VALIDATION' store and space
    default VALIDATION_STORE_TYPE "Kxen.FileStore"
    default VALIDATION_STORE_NAME "D:\DATA/199710"
    default VALIDATION_STORE_USER $STORE_USER
    default VALIDATION_STORE_PWD $STORE_PWD
    default VALIDATION_STORE_ALIAS myValidationStore
    default VALIDATION_SPACE "model219.txt"
    default MODEL_SAVE_STORE_TYPE "Kxen.FileStore"
    default MODEL_SAVE_STORE_NAME "."
    default MODEL_SAVE_STORE_USER ""
    default MODEL_SAVE_STORE_PWD ""
    default MODEL_SAVE_NAME "target_model219.bigtrain"
    default MODEL_SAVE_SPACE "target_model219.kxen"
    default MODEL_SAVE_COMMENT "The model 'target_model219.bigtrain' has been saved"
    createModel Kxen.SimpleModel m
    m.getParameter ""
    m.changeParameter Parameters/CutTrainingPolicy "random"
    m.setName "target_model219.bigtrain"
    m.validateParameter
    etc
    I can see that the ESTIMATION and VALIDATION data sets are now defined, but the policy still says "random". Does this matter? Should I override the value? I can't find anything in the API docs.
    Thank you,
    Scott

    Can anyone tell me if I've posted this in the correct forum?
    Thanks,

  • 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

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

  • How to write dbms_out traces into a file (in a shell script)?

    I'm afraid this is a shell scripting question:
    I have the following lines in a script:
    ls $salida/EXAR* | while read FILE
    do
    sqlplus -s user@isntance/password << EOF
    set serveroutput on size 1000000
    set feedback off
    --set trimspool on
    var p_out_result_nv number
    var p_out_DescError_SV varchar2(4000)
    var p_out_Traza_SV varchar2(4000)
    var p_Fich_Entrada varchar2(4000)
    --spool $mi_fich_log
    begin
    :p_Fich_Entrada := replace(('$FILE'),('$salida/'),'');
    dbms_output.put_line('Tratando archivo: '||:p_Fich_Entrada);
    :p_out_result_nv := 0;
    SJPAMIOB.SJPRPRIN('01',:p_Fich_Entrada,:p_Fich_Entrada,'EXSJ_ENTRADA','EXSJ_SALIDA',
    :p_out_result_nv,:p_out_DescError_SV,:p_out_Traza_SV);
    end;
    --spool off
    exit :p_out_result_nv
    EOF
    How can I write all dbms_output.put_line in a file?
    Thanks in advance.

    you can use the package utl_file.
    for this you either
    - need a directory object in the database which points to the folder where your file is located you want to write to:
    CREATE DIRECTORY lutz_dir AS ´/home/oracle/UTL_FILE_DIR´;
    You will need create any directory privilege for this.
    or
    - you must have the init.ora parameter UTL_FILE_DIR set to the location.
    Regards,
    Lutz

  • Beginner question - testing for null string from shell script command

    I'm trying to test the result of a shell script command. I want to put out a message if the result is a null string. At present I get this applescript error "The command exited with a non-zero status"
    I'm sure this is a simple question ... but I can't figure out how to do it. Help!

    You can use try clause for the problem:
    set _result to ""
    try
    set _result to do shell script "/blah/andblah"
    end

  • Editing question, preferably with "do shell script"

    I would like to edit an expression
    from: blah blah /Paragraphs/one two three
    to: blah blah /Paragraphs/one-two-three
    where "/Paragraphs/" is always present
    but "one" might be anything
    Using sed with regexp seems like a way to go, but I don't know how to designate "one," which will vary. Viz.:
    set T to "blah blah /Paragraphs/one two three"
    set T1 to do shell script "echo " & quoted form of T & " | sed 's/\\/Paragraphs\\/{anything}/\\/Paragraphs\\/{anything}(change all subsequent spaces to "-")/g'"

    Hi,
    Can't believe I did it with sed! My test.txt file looks like this:
    blah blah #one here's some text
    blah blah #two more text
    blah blah #three and even more text
    #four number begins this line
    Here's the sed part:
    sed 's/#/\
    #/' < test.txt | sed '/#/ s/ /-/g' | sed '
    N
    s/\n#/#/
    Here I used "#" instead of "/Paragraphs/". Now, you translate this into a do shell script. If you need help with that, then write back. I now understand the N command for working with multiple line processing. Here's the tutorial I used:
    http://www.grymoire.com/Unix/Sed.html
    Edited: and here's the output
    blah blah #one-here's-some-text
    blah blah #two-more-text
    blah blah #three-and-even-more-text
    #four-number-begins-this-line
    gl,

  • .sh shell script Xcode question

    So in my application I'd like to include a shell script and have a button execute it
    for the sake of keeping things simple lets say the shell script is "mkdir ~/1234"
    Now I have the button on the interface and i have the shell script saved in a file named script.sh
    how to I make the button execute the shell script
    (also I would like to do this without using applescript)

    Have a go at this tutorial. There really isn't a simple way we can explain how to do what you need. It's not hard, but there are several critical things you need to learn.
    http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjCTutori al/01Introduction/01Introduction.html
    Best of luck.
    Eric

  • Two questions regarding shell scripts in automator

    they are both concerning this script:
    I pass it an .avi file (I believe it could also take more than one), and outputs a converted file (that is playable on appletv2) that is dumped in my "Converted" folder.  This all works fine and dandy.
    However, I would like to have it prompt the user for a destination folder, and pass that in as well.  However, I do not know how I would refer to that variable separately.
    Handbrake's CLI application also produces output that shows what percentage the conversion is at, and although the script passes this output as it's own output (to the next automator action - I actually discovered this only by accidentally leaving a "Speak Text" action in), I want to be able to see this output in real time.  Is there anyway to do this?  Thanks for the help!

    To be clear, this is what you mean, correct?
    for outpath; do :; done
    for f in "$@"
    do
        if [ "$f" != "$outpath" ];
              thenof="$outpath"/`basename "$if" .avi`.mp4
        /Applications/HandBrakeCLI -i "$if" -o "$outpath" --preset="AppleTV 2"
        fi
    done
    I assume that "Ask For Finder Items" also passes it's input along to the next action?  Would "Get Value of Variable" do the same thing?  (I also use the same workflow to convert .mkv files and copy .srt files to the same destination folder, so I need to access the source files multiple times to filter out different files each time).
    I would just test it myself, but I am not at my computer right now.
    And this is kind of off topic, but since automator actions can be written in shell script, could this be easily made into one? How much work would it involve? 

  • Shell scripting basic question

    I wrote as shell script .p02ibm to set my env but its not working when i run it, wondering what i am doing wrong?
    [oracle@localhost ~]$ echo $SHELL
    /bin/bash
    vi .p02ibm
    ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
    export ORACLE_HOME
    PATH=$ORACLE_HOME/bin:$PATH
    export PATH
    ORACLE_BASE=/u01/app/oracle
    export ORACLE_BASE
    ORACLE_SID=p02ibm
    export ORACLE_SID
    EDITOR=vi
    export EDITOR

    Just curious why you are creating a new file when you probably should be adding the oracle user's enviroment variables to the .bash_profile in the $HOME directory.
    The shortened setting method is:
    export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
    Normally you would add them under this section (in the .bash_profile):
    # User specific environment and startup programs
    Rick

  • Sending an email using shell script in Oracle Applications

    Hi,
    I have a pl/sql package which will call a shell script program.The shell script program is written in order to send the invoice hold details of AP as a mail.The parameters to this program are passed in the pl/sql package.
    The shell script program has
    5 parameters namely
    to - email
    from - email
    hold id - which is a number
    hold name - varchar2( free text)
    hold reason - varchar2( free text)
    the shell script looks as below.
    FROM_EMAIL=`echo $1|cut -f9 -d " "|sed 's/\"//g'`
    echo "From email id is $FROM_EMAIL" -- From email
    TO_EMAIL=`echo $1|cut -f10 -d " "|sed 's/\"//g'`
    echo "To Email id is $TO_EMAIL" -- to email
    PARAM0=`echo $1 | awk '{print $11}'|sed -e "s/\"//g"`
    echo "Param0: $PARAM0" -- hold id
    PARAM1=`echo "$1" | cut -d" " -f12-| sed -e "s/\" \"/\"^\"/g" | awk -F'^' '{print $1}'|sed -e "s/\"//g"`
    echo "Param1: $PARAM1" -- hold name
    PARAM2=`echo "$1" | cut -d" " -f13-| sed -e "s/\" \"/\"^\"/g" | awk -F'^' '{print $1}'|sed -e "s/\"//g"`
    echo "Param2: $PARAM2" -- hold reason
    the values that am passinf to this program are if suppose
    from email ---- [email protected]
    to email [email protected]
    12345 ------ hold id
    test hold name ------ hold name
    test hold reason ------- hold reason

    Is there a question here?
    In any case you could easily have done this inside the database using UTL_SMTP.

  • Calling a report from unix shell script

    Hi,
    I had to call a report from unix shell script.
    May i know the procedure to accomplish this
    Thanks in Advance
    A.Gopal

    First you should not include the whole path to your report in the call ...
    Use like this:
    /ora/u01/oracle/v101/as2/bin/rwrun.sh report=an_stati destype=file desname=/ora/u01/oracle/v101/as2/test.pdf desformat=pdf
    In $ORACLE_HOME/bin/reports.sh:
    1) Verify that you have updated the REPORTS_PATH variable to include your folder where you have the report in question
    REPORTS_PATH=/ora/u20/app/qits/env1/run:$ORACLE_HOME/reports/templates:$ORACLE_HOME/reports/samples/demo: ....
    2) Verify that the REPORTS_TMP variable is pointing to a valid location and that the oracle user has access to write on it.
    After that, post the content of the tracefile located at $ORACLE_HOME/reports/logs/{in-process report server name folder}/rwserver.trc
    If no file is present then it means that you need to enable trace in your reports's conf file.... go to the $ORACLE_HOME/reports/conf folder and and locate the .conf file that correspond to your in-process reports server name (as specified in the rwservelet.properties file)... open/edit the file to enable trace logs ..
    i.e.
    Change the following line:
    <!--trace traceOpts="trace_all"/-->
    to <trace traceOpts="trace_all"/>
    Bounce the reports server and try to run the report again, this time the .trc file should be generated, post the content so that we can take a look.

  • How can i pass parameter values from html to a shell script

    Hi Guys...
    I had a requirement where i need to execute a sql statement and print the output in HTML page. This report has parameters to enter. So i created a HTML form which accepts parameters. When the submit button is pressed, the action tag in the form invokes unix shell script file. It will open sqlplus and run the sql script file .sql and print the output in the HTML page.
    sql script contains the query and some set options which prints the output in HTML page. Like "SET MARKUP HTML ON"... The query has some parameters like "select * from emp where empno = &&empnumber. I will use the same name "empnumber" while created the HTML parameter form like " <input type = "text" name="empnumber" size="10" align="left">.
    user sees this parameter form and enters some value in to that empno text box.
    My question is how can i catch these parameter values in a shell script and pass it to the sql script to execute it.
    Help Appreciated
    Thanx

    This is a A Bad Idea (tm). This type of CGI processing is old and were (and still is) full of security holes. Very easy to inject stuff (Unix commands and SQL) into it.. To get those parameters into SQL*Plus requires using Unix shell commands to process it - and something like a backquote allows all kinds of nasty stuff to be injected. The Unix shell was never designed to be used as a secure CGI environment.
    There are far better and far superior alternatives. Perl (with Perl_DBI) and PHP (using Zend Core for Oracle) come to mind as web scripting languages.
    Even easier is using HTMLDB. Very few moving parts. Is free. Supports Oracle 9.2 and 10G.

  • Can any one tell me how can i call a shell script from pl/sql

    i like to call shell script from pl/sql procedure.
    can any one suggest how can i do this

    Have you not mastered in asking the same kind of question ?
    First do write a script...
    no one will spoon feed you.
    How can i call a shell script from procedure
    How to call Shell Script from pl/sql block
    -Sk

Maybe you are looking for

  • IMac 24" Buzz

    Hi. I just purchased a new iMac 24" and in the last week or so it has developed a buzz. The buzzing is strange because as far as I can tell, it is not associated with the brightness of the screen. It is also not a steady sound but one that comes and

  • Profit center wise report using MB51

    Dear experts, I want to copy standard report of MB51 which is RM07DOCS. In this report I want profit center field also . Profit field exists in table MSEG. where I have to attach this field in the report RMO7DOCS. This report is heirarchical report.

  • Compiling Issue on SUNstudio11

    Server : Sunfire x4100 O/S : Solaris10 Error: While compiling im getting the following error. $ compile Cleaning *.o, *.c, recon *.o: No such file or directory recon: No such file or directory Compiling init.pc to init.c Pro*C/C++: Release 10.2.0.2.0

  • Finder: Safari Community Toolbar Issue

    While searching through Finder I will almost always receive a pop-up window that is titles "Community Toolbar" It then proceeds to inform me that the Safari I am currently running is out of date and the toolbar cant be opened. However everything on t

  • Check if my z3 is genuine.

    Hi, I just bought a xperia z3 on some local store here in the PH. Can you check if its genuine or not? Cause we want to try it in the water, although, the store said its not part of their warranty if it will get broke when we test it in the water. IM