Passing variables to CONNECT command

I am on Oracle 8.1.6.
Here is my incomplete sample code :
set serveroutput on
var passw varchar2(200);
define login = 'CDM1';
DECLARE
sql_stmt VARCHAR2(200);
emp_schema varchar2(10) := 'CDM1';
emp_passw varchar2(10) ;
BEGIN
:passw := aps_sec_pkg.get_pw('cdm1');
dbms_output.put_line ('password is --'||:passw);
emp_passw := :passw;
dbms_output.put_line ('password is --'||:passw);
END;
How do pass variables to the CONN command so that
conn $emp_schema/$emp_passw
will work.
Define command does not accept variables.
How can I accomplish this ?

There's probably an easier way but here's what occured to me...
variable schema_bind varchar2(10);
exec :schema_bind := 'MY_SCHEMA';
column schema new_value schema_var;
select :schema_bind as schema from dual;
prompt &&schema_var;Richard

Similar Messages

  • Passing variables to fs command

    Im building a presentation that pulls urls from a xml file and assign them to a button on and offline....im using fscommand for offline links but how do i
    send a variable to fscommand being that for each node in the xml file there is a offline link..that gets passed to a variable...can i pass that vairble to fscommnd?
    I tried this fscommand('exec' 'currentCDLink'); i got a syntax eror saying i need to put a right peren before the variable.. that dont make sense...
    help Please
    Thank you

    There's probably an easier way but here's what occured to me...
    variable schema_bind varchar2(10);
    exec :schema_bind := 'MY_SCHEMA';
    column schema new_value schema_var;
    select :schema_bind as schema from dual;
    prompt &&schema_var;Richard

  • How to change button names linked with the 'connect command?'

    Hi,
    I have linked a button in the sequence view to the Exeution entry point 2 (Single Pass) using the 'Connect command'. The button now displays 'Single Pass' as its caption name while running. I want to give a custom name to this button, but it should still be connected to the single pass function. How can rename it?
    Regards
    Gopal

    Hi,
    see this link: http://forums.ni.com/ni/board/message?board.id=330&message.id=7318&query.id=380755#M7318
    You will find the Text for the buttons in one of the ini files. Use the CustomStrings.ini to define your new text, which will override the text defined in the other ini file located in the NI folder when the Operator Interface or SeqEditor first launched and loads the various resources.
    Hope this helps
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • Passing variable having value as whole SOAP request to command while invoking ODI WS call

    When passing variable in place of soap request message (variable value is whole SOAP request message prepared using procedure) in ODI Invoke WebService command like -->
    OdiInvokeWebService "-URL=url...." "-PORT_TYPE=..." "-OPERATION=..." "-RESPONSE_MODE=NEW_FILE" "-RESPONSE_FILE_CHARSET=UTF8" "-RESPONSE_XML_ENCODING=UTF-8" "-RESPONSE_FILE=..." "-RESPONSE_FILE_FORMAT=SOAP" "-HTTP_USER=..." "-HTTP_PASS=..."
    #SOAPREQUESTMESSAGE
    Gives error :
    ODI-1226: Step OdiInvokeWebService 1 fails after 1 attempt(s).
    ODI-1241: Oracle Data Integrator tool execution fails.
    Caused By: com.sunopsis.wsinvocation.SnpsWSInvocationException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '#' (code 35) in prolog; expected '<'
    at [row,col {unknown-source}]: [1,1]
        at com.sunopsis.wsinvocation.client.impl.AbstractMessageImpl.loadFromXML(AbstractMessageImpl.java:333)
        at com.sunopsis.wsinvocation.client.impl.AbstractMessageImpl.loadFromString(AbstractMessageImpl.java:348)
        at com.sunopsis.wsinvocation.client.impl.AbstractMessageImpl.fromString(AbstractMessageImpl.java:403)
        at com.sunopsis.wsinvocation.client.impl.AbstractJWSDLParserImpl.fromXML(AbstractJWSDLParserImpl.java:272)
        at com.sunopsis.wsinvocation.client.impl.AbstractJWSDLParserImpl.getWebServiceRequestByOperation(AbstractJWSDLParserImpl.java:260)
        at com.sunopsis.dwg.tools.common.WebserviceUtils.getSOAPMessage(WebserviceUtils.java:94)
        at com.sunopsis.dwg.tools.common.WebserviceUtils.invoke(WebserviceUtils.java:138)
        at com.sunopsis.dwg.tools.InvokeWebService.actionExecute(InvokeWebService.java:327)
        at com.sunopsis.dwg.function.SnpsFunctionBase.execute(SnpsFunctionBase.java:276)
        at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execIntegratedFunction(SnpSessTaskSql.java:3437)
        at com.sunopsis.dwg.dbobj.SnpSessTaskSql.executeOdiCommand(SnpSessTaskSql.java:1509)
        at oracle.odi.runtime.agent.execution.cmd.OdiCommandExecutor.execute(OdiCommandExecutor.java:44)
        at oracle.odi.runtime.agent.execution.cmd.OdiCommandExecutor.execute(OdiCommandExecutor.java:1)
        at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)
        at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2913)
        at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2625)
        at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:558)
        at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:464)
        at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2093)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$2.doAction(StartSessRequestProcessor.java:366)
        at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:300)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$0(StartSessRequestProcessor.java:292)
        at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$StartSessTask.doExecute(StartSessRequestProcessor.java:855)
        at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:126)
        at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:82)
        at java.lang.Thread.run(Thread.java:662)
    Thanks in anticipation...

    the used variable 'SOAPREQUESTMESSAGE' is being created in a procedure using jython.
    1. Can we use this variable (SOAPREQUESTMESSAGE) value in the next step that is while invoking web service request (can it persist) ?
    2. If not then how can we use this variable value to invoke ws request in next step ?
    Would like to appreciate help.
    Pls reply.

  • Passing variables from shell script to separate sqlplus script

    Hi, I am having issues passing variables to a separate sqlplus script invoked by the shell script, e.g.
    #!/bin/sh
    DB_NAME=TEST
    PWD1=PA55W0rd
    echo exit | sqlplus / as sysdba @${DB_NAME}.sql ${DB_NAME} $PWD1 >> ${DB_NAME}.sql
    exit 0
    The script picks up the $DB_NAME variable fine, and therefore invokes the required sql script.
    However, when I pass the variable $PWD1 to the sql script I get an error.
    The script creates a database link:
    create or replace procedure new.link
    is
    begin
    execute immediate 'create database link TEST
    connect to TESTSCH identified by '$PWD1'
    using ''TEST''';
    end;
    exec new.link;
    output is:
    ERROR at line 1:
    ORA-00911: invalid character
    ORA-06512: at "NEW.LINK", line 4
    ORA-06512: at line 1
    any help appreciated!
    Edited by: 969765 on Apr 5, 2013 4:24 AM

    969765 wrote:
    that is a pretty unhelpful comment, this is actually my LAST resort I have looked up all the documentation etc.This is what I did...
    I went to the documentation:
    http://www.oracle.com/pls/db112/homepage
    I searched for "sqlplus" which gave me this documentation (under "SQL*plus program syntax")...
    http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_three.htm#i1169374
    I read the syntax:
    SQLPLUS [ [Options] [Logon|/NOLOG] [Start] ]and the subsequent information:
    >
    where Start has the following syntax:
      @{url|file_name[.ext]} [arg ...]and "Start" was hyperlinked, so I clicked on it, which took me to the section...
    >
    Start
    @} [arg ...]
    Specifies the name of a script and arguments to run. The script can be called from the local file system or from a web server.
    SQL*Plus passes the arguments to the script as if executing the file using the SQL*Plus START command. If no file suffix (file extension) is specified, the suffix defined by the SET SUFFIX command is used. The default suffix is .sql.
    See the START command for more information.
    >
    and here the "START" was hyperlinked, so I clicked on that...
    and hey presto, I ended up here:
    http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve044.htm#BACJJHDA
    ... where the arguments are described...
    >
    arg ...
    Data items you wish to pass to parameters in the script. If you enter one or more arguments, SQL*Plus substitutes the values into the parameters (&1, &2, and so forth) in the script. The first argument replaces each occurrence of &1, the second replaces each occurrence of &2, and so on.
    >
    ... clearly explaining that SQL*Plus substitutes the substitution variables &1, &2 etc. in the script with the passed in arguments.
    Your script was including a Unix style substitution, not an SQL*Plus script substitution, so that's seems to be the most likely cause of your problem.
    And still you haven't come back to say whether it's worked for you or not... leaving others guessing as to whether you still need help.

  • Error produced when trying to pass variables to a Matlab script

    For some reason, LabVIEW produces an Error 1047 (Unable to pass variable to the script server) whenever I create an input variable to a Matlab code block.
    Outputs work fine (for example, connecting an output "a" to a Matlab code block that says "a=rand(50)" correctly produces a 50x50 array of random numbers that can be displayed in LabVIEW). However, creating any kind of input node, whether or not the associated variable is mentioned in the MATLAB script, brings up an error 1047.
    Any ideas what could be causing this? I'm using LabVIEW 7.0 and MATLAB 7 (R14). I've read the article
    >here and that's not the problem, and I've also updated my matscript.dll to the latest version, 7.0.0.2, which also made no difference.

    For what its worth,
    I work in a company with a lot of Matlab users, and I,m programming in Labview and Matlab.
    When I create a testrig measurement I always have to convert data into Malab format, so I used the script server a lot... exept we have a limited pool of Matlab
    licenses so my work was halted whenever the licences where gone.
    So I wrote a Write2Matlab vi.
    This vi can log data from a measurement and write it in a Matlab readable file format (Matlab6 R12).
    After logging you can append more data. It works with(Double,Single,Int32,Int16,U16,U8,String) matrix see for yourself in an example (Write2matlab_test.vi).
    Perhaps this is an alternative solution for your problem.
    Please send me a reply if you find it usefull.
    John
    Attachments:
    Write2Matlab.llb ‏1145 KB

  • Issue passing variable into shell script

    Please see terminal session.
    -  calling pwd, unset, or echo alleviate the issue.
    - running the script 'plain' also exihibit an issue
    - calling 'cat test.sh' causes an issue
    I can repeat the issue on OSX 10.5.8
    On Ubuntu, two a's always print out with: A=a B=$A ./test.sh
    Terminal session:
    bash-3.2$ ls -l test.sh
    -rwxr-xr-x  1 axure  staff  16 Mar 29 09:27 test.sh
    bash-3.2$ cat test.sh
    echo $A
    echo $B
    bash-3.2$ pwd
    /Users/axure
    bash-3.2$ A=a B=$A ./test.sh
    a
    a
    bash-3.2$ A=a B=$A ./test.sh
    a
    bash-3.2$ $A
    bash-3.2$ $B
    bash-3.2$ echo $A
    bash-3.2$ echo $B
    bash-3.2$ unset
    bash-3.2$ A=a B=$A ./test.sh
    a
    a
    bash-3.2$ A=a B=$A ./test.sh
    a
    bash-3.2$ pwd
    /Users/axure
    bash-3.2$ A=a B=$A ./test.sh
    a
    a
    bash-3.2$ A=a B=$A ./test.sh
    a
    bash-3.2$ unset
    bash-3.2$ cat test.sh
    echo $A
    echo $B
    bash-3.2$ A=a B=$A ./test.sh
    a
    bash-3.2$ unset
    bash-3.2$ A=a B=$A ./test.sh
    a
    a
    bash-3.2$ A=a B=$A ./test.sh
    a
    bash-3.2$ unset
    bash-3.2$ ./test.sh
    bash-3.2$ A=a B=$A ./test.sh
    a
    bash-3.2$

    bash-3.2$ ls -l test.sh
    -rwxr-xr-x  1 axure  staff  16 Mar 29 09:27 test.sh
    bash-3.2$ cat test.sh
    echo $A
    echo $B
    bash-3.2$ pwd
    /Users/axure
    bash-3.2$ A=a B=$A ./test.sh
    a
    a
    As I would expect
    bash-3.2$ A=a B=$A ./test.sh
    a
    NOT what I would expect.  I tested this using bash 3.2 and got the same results, HOWEVER, when I tested this with bash 4.0, I got what I expected, namely your first results everytime.
    So I think there is a bug in bash 3.2.  You can get the bash sources, and build your own bash if you wish, or use a different method of setting 1 time envionment variables for use in a subprocess.
    bash-3.2$ $A
    bash-3.2$ $B
    bash-3.2$ echo $A
    bash-3.2$ echo $B
    As expected, as the way you set A & B were as 1 time environment variables that were only seen by the subprocess created when test.sh was run.  A & B were NOT created in the current shell environment, so the current shell environment would not have any values for A & B
    bash-3.2$ unset
    bash-3.2$ A=a B=$A ./test.sh
    a
    a
    bash-3.2$ A=a B=$A ./test.sh
    a
    Again, now what I would expect, but as I have already stated, I think there is a bug in bash 3.2 that does not exist in bash 4.0.
    Now a bigger question, why are you passing A & B as 1 time envionment variables?  Why not just pass them on the command line?
    test.sh a a
    where test.sh would be
    echo $1
    echo $2
    Or you could use export to create environment variables A & B
    export A=a
    export B=$A
    test.sh
    Now A & B would still exist after test.sh, which I assume you do not want to do.
    You could try ceating test.sh as a bash function and see if that changes the behavior
    test()
        echo $A
        echo $B
    A=a B=$A test
    You would have to define test() in your shell initialization scirpt if you needed each time you started a terminal session.
    While I have used 1 time environment variables, I more frequently just pass arguments on the command line.

  • Use of variables in connection pools

    Are there any other reasons to use variables in Connection Pool definitions other than if there are multiple CPs using a single DB ?
    I'm reading various articles about migration between environments (eg http://obieeblog.wordpress.com/2009/08/04/simplifying-migration-process-%E2%80%93-changing-environment-specific-variables-in-rpd/ and http://oraclebizint.wordpress.com/2008/05/02/oracle-bi-ee-101332-automating-password-updates-of-connection-pools-and-users-command-line-options/) and it's struck me that the variables don't appear to add much benefit.
    thanks.

    Hi,
    I have two databases that are identical except in name. They have the same tables, same views etc.
    Right now, I have them in two separate database folders in the Physical Layer each with its own connection Pool. So, When I create Reports in answers or dashboards, I have create two of them.
    How Can I just create one report and make it point to the proper database dynamically.?
    Thanks,
    rkingmdu

  • How to pass variable to SQLPLUS in a ksh script?

    Hi,
    I am writing a ksh script which will use sqlplus to run a sql and pass 2 variables as the SQL request. In the ksh script, I have 2 variables which are $min_snap and $max_snap holding 2 different numbers.
    Inside the same script, I am using SQLPLUS to run an Oracle SQL script, which request to enter 2 set of numbers, one at a time. Normally running situation, I can enter the number from the keyboard, but since I am writing a script, I want to pass those numbers by passing variables in the script? How can I do it?
    Please help!
    here is my ksh script,
    #!/bin/ksh
    if [ "$1" = "" ]
    then
    echo "Usage : delete_snapshot.sh <db_name>"
    exit
    fi
    export ORACLE_BASE=/oracle1/app/oracle
    export ORACLE_PATH=.:/oracle1/app/oracle/product/8.1.7/tune
    export ORACLE_HOME=/oracle1/app/oracle/product/8.1.7
    export ORACLE_RDBMS=$ORACLE_HOME/rdbms/admin
    export ORACLE_SID=$1
    curr_time=`date +"%m/%d/%y %H:%M:%S"`
    log_file=/home/mdbtuner/stats/sppurge/log/{$ORACLE_SID}_`date +"%Y%m%d"`.log
    #echo $log_file
    echo "****** Delete Snapshot for $ORACLE_SID at $curr_time ******" >> $log_file
    #echo "****** Delete Snapshot for $ORACLE_SID at $curr_time ******"
    #echo $ORACLE_HOME/bin/sqlplus -S perfstat/perf$ORACLE_SID@$ORACLE_SID
    cd /home/mdbtuner/stats/sppurge
    $ORACLE_HOME/bin/sqlplus -S perfstat/perf$ORACLE_SID@$ORACLE_SID << EOF > $min_snap
    @min_snapid.sql
    exit;
    EOF
    $ORACLE_HOME/bin/sqlplus -S perfstat/perf$ORACLE_SID@$ORACLE_SID << EOF > $max_snap
    @max_snapid.sql
    exit;
    EOF
    echo $min_snap $max_snap
    cd $ORACLE_RDBMS
    #$ORACLE_HOME/bin/sqlplus -S perfstat/perf$ORACLE_SID@$ORACLE_SID << EOF >> $log_file
    $ORACLE_HOME/bin/sqlplus -S perfstat/perf$ORACLE_SID@$ORACLE_SID << !
    @sppurge
    $min_snap
    $max_snap
    exit;
    #EOF
    Thanks in advance!
    Robert
    Message was edited by:
    user168

    Thank you for response, Paul.
    Have you ever used statspack? or sppurge.sql?
    When you run $ORACLE_HOME/rdbms/admin/sppurge.sql, it waits for user to enter losnapid and hisnapid manually from the keyboard.
    My trouble is to have a script to delete old snapshot which are 3 weeks old. So I create min_snapid.sql and max_snapid.sql to hold two variables.
    Based on your solution, I tried it but it doesn't work.
    It returns the error messages as following....
    Warning
    ~~~~~~~
    sppurge.sql deletes all snapshots ranging between the lower and
    upper bound Snapshot Id's specified, for the database instance
    you are connected to.
    You may wish to export this data before continuing.
    Specify the Lo Snap Id and Hi Snap Id range to purge
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Enter value for losnapid: Using exit; for lower bound.
    Enter value for hisnapid:
    User requested Interrupt or EOF detected.
    Enter value for hisnapid:
    User requested Interrupt or EOF detected.
    WARNING: LoSnapId or HiSnapId specified does not exist in STATS$SNAPSHOT
    Enter value for hisnapid:
    User requested Interrupt or EOF detected.
    Purge of specified Snapshot range complete. If you wish to ROLLBACK
    the purge, it is still possible to do so. Exitting from SQL*Plus will
    automatically commit the purge.
    -------------------------------------------

  • Using The Connect Command

    Hi,
    If i want to connect from one instance to several instances then from SQL plus I can use connect command and connect one by one.
    But when i am writing a PL SQL package does the same trick works?
    means For Instance A(sysdate :: 22/07/07) and B(sysdate:: 21/07/07)
    If the package is in B
    then
    BEGIN
    DBMS_OUTPUT.PUT_LINE(TO_CHAR(SELECT SYSDATE FROM DUAL));
    CONNECT B (USER/PASS);
    DBMS_OUTPUT.PUT_LINE(TO_CHAR(SELECT SYSDATE FROM DUAL));
    DISCONNECT;
    END;
    WILL IT PRINT TWO DIFFERENT DATE??
    Pls Advice..
    Thanks in advance..
    Thanks,
    Ru

    The Statement that I used is just for explanation. I didn't tried it to print. However DBLinks couldn't be created. This Package is Only for Reproting Purpose and Creating DBLINK will Not be Allowed.
    Besides If a new Instance Comes into Picture Then I have to create DBLINK for that also.
    When SQL plus connect to a instance using TNS entry-- I want to know how the connection object is achieved and used. IP/Prot/SID/User/pass will be provided by User.
    Let me explain the problem first. I want a Package in one instance. It has a procedure to generate a report. Now all the instances are identical. So, the package will connect to any instance and thus the report could be generated for any instances without deploying the package in each instance.
    Plesae assist me what should be the best approach.(DBLINK Couldn't be created)
    Thanks in advance..

  • How to pass variable in the place of numeric value?

    Hi,
    my requirement is i want to validate the selection screen block width.
    I have created tabbed selection screen.
    i need in which variable tab lengh values will be stored
    ex:-
    selection-screen: begin of tabbed block MYTAB for 10 lines,
                      TAB (20) button1 USER-COMMAND push1,
                      TAB (20) button2 USER-COMMAND push2,
    end of block MYTAB.
    here in the above code i want to pass variable instead of directly numeric value as 10.
    because based on some conditions i want to change the number of lines.
    how to do this...plz urgent, i will give all the points to anybody who given good answer.
    Thanks in Advance,
    venkat n

    Hi!
    And that's why God created macros.
    DEFINE seltab.
    selection-screen: begin of tabbed block MYTAB for &1 lines,
    TAB (20) button1 USER-COMMAND push1,
    TAB (20) button2 USER-COMMAND push2,
    end of block MYTAB.
    END-OF-DEFINITION.
    DATA: lv_lines TYPE i VALUE 10.
    seltab lv_lines.
    Regards
    Tamá

  • Passing variable from one template to another

    We have problems in the BI7 environment with passing variables across from one web template to another.
    In BW3.x there was a Java Script Command SAP_BW_URL_Get used to construct URLs.
    (Please also see the SAP documentation: http://help.sap.com/saphelp_nw04/helpdata/en/b4/0fa239cec06b40e10000000a11402f/content.htm)
    In BI7 this command seems to be not existent.
    But as it is such a basic functionality I can’t believe that is not available anymore.
    I guess it is replaced by another command.
    Could you help us to find a functionality that replaces the SAP_BW_URL_Get command?

    Hi Andrew,
    Did you manage to find any solution for this one?
    Currently we are also facing the same problem.
    Thank you in advance.
    Best regards,
    Fen

  • Passing variables from one swf to another

    I am facing problem to pass variable from one swf to another.
    I am using loadMovie to load another swf. how can I pass a variable
    value to another swf. Can anyone help me plz? It is somewhat
    urgent.
    thanx in advance.

    first of all:
    this is the Flash Media Server and your problem is not
    related to FMS....
    second thing related to the "somewhat urgent" :
    we, users on this forum, are not there to do your job... so
    calm down otherwise no people will answer your question. This forum
    is a free support forum that community of Flash developer use to
    learn tricks and to solve problems.
    Possibles solutions:
    If the two swf are seperate you can use LocalConnection to
    establish a connection between different swf.
    If you load a second swf into the first one you can interact
    like a standard movieClip(only if there from the same domain or if
    you a policy file on the other server)
    You can use SetVariable(via Javascript) to modify a root
    variable on the other swf and check with an _root.onEnterFrame to
    see if the variable had changed in the second swf.
    * MovieClipLoader will do a better job, in your specify case,
    than the loadMovie. Use the onLoadInit event to see when the swf is
    really totaly loaded into the first one otherwise you will have
    timing issues.
    My final answer(lol) is the solution 2 with the
    notice(*)

  • Sqlplus connection command

    I have a database installed on my machine.I created an entry in tnsnames.ora. entry name is "test"
    I'm able to connect to it using sql developer.
    I'm able to connect to my database using sql plus locally:
    sqlplus user/pass@testhowever, I'm not able to connect using locally:
    sqlplus user/pass@//IP:port/sidgot error:
    ORA-12154: TNS:could not resolve the connect identifier specified
    from another machine,I'm able to connect to database using 2nd sqlplus connection command.
    Why was that? why the same command does not work on my local mahicne?
    also, I tried to connect to others database on others machine, the sqlplus command is not working either although connection works in sql developer.
    seems something wrong with my sql plus.

    my bad, the connection information in the command was wrong
    please ignore this.

  • Passing variables from Applescript to bash

    Hello,
    I'm trying to pass variables from Applescript to bash using the following code
    #!/bin/bash
    osascript <<EOF
    tell application "SystemUIServer"
    set username to text returned of (display dialog "Enter your name" with icon caution default answer ""  buttons{"Continue"})
    set macname to text returned of (display dialog "Enter name of your Mac" with icon caution default answer ""  buttons{"Continue"})
    do shell script "export USERNAME=" & quoted form of username & " && export MACNAME=" & quoted form of macname
    end tell
    EOF
    echo "USERNAME is $USERNAME, MACNAME is $MACNAME"
    but no luck
    Mac-mini:Downloads admin$./new.command
    USERNAME is , MACNAME is
    Any help would be greatly appreciated.

    I just realized you are returning 2 variables.  That can still be handled by echoing/printing the values, you just have to parse the output, or use other tricks.
    VALUES=( $(osascript -e '...') )
    This would make VALUES an array, with each array element containing one space separate return value from osascript
    USERNAME=${VALUES[0]}
    MACNAME=${VALUES[1]}
    If USERNAME or MACNAME could have spaces in them, you would need to use some kind of separator character.  For example if you use @ as the separator you could do something like:
    VALUES=$(osascript -e '...')
    USERNAME=${VALUES%@*}
    MACNAME=${VALUES#*@}
    which will %@* will delete everything starting with the @ til the end of the string, and #*@ will delete everything from the beginning of the upto and including the @.
    Another trick is to have the return values be properly formed shell variable assignments such as
    print "USERNAME='your user name' MACNAME='Your Mac Name' " -- I'm making this up as I do not really know Applescript, so you will have to figure out how to get Applescript to print something that looks like
    USERNAME='your user name' MACNAME='Your Mac Name'
    In your shell script you have code that looks like:
    VALUES=$(osascript -e '...')
    eval $VALUES
    The eval will execute whatever is stored in $VALUES, and if that happens to look exactly like shell variable assignments, you get the variables created in the current shell context, where can use them.

Maybe you are looking for