Informix

Informix

Connect with Db2, Informix, Netezza, open source, and other data experts to gain value from your data, share insights, and solve problems.

 View Only
  • 1.  Error "Variable syntax" on shell command within SQL script

    Posted 2 hours ago

    Greetings family.

    I started writing this in order to present a problem I was having.  But while articulating my problem I hit on a workaround that mostly works.  I am posting it because I think it may solve a similar problem for someone else.

    I have an SQL script that runs a bunch of delete commands.  I want to pepper it with messages and time stamps. Logging in as myself I can do this:

    dbaccess sysmaster -

    > !echo Delete from table yutz at $(date +"%Y-%m-%d %H:%M:%S")
    Delete from table yutz at 2026-09-22 11:48:28

    So it works as I would like it to in the script.  I peppered the SQL script with the same !echo command.  I got these errors at every !echo command:
    stty: : No such device or address
    stty: : No such device or address
    stty: : No such device or address
    stty: : No such device or address

    Variable syntax

    Ok, lemme back up and run this in an interactive dbaccess session, as user informix this time. (The script MUST run as user informix.) 

    dbaccess sysmaster -

    Database selected.

    > !echo Delete from table yutz at $(date +"%Y-%m-%d %H:%M:%S")
    Variable syntax

    Well, at least no stty messages.  The main difference between my login and the informix login is that my default shell is ksh and informix's shell is csh.  But I get the same error even when I have exec's to ksh before starting the dbaccess session.  It would appear that each !echo command is spawning a C-shell and csh does not like that command.  I tested this as myself running csh:

    % echo Delete from table yutz at $(date +"%Y-%m-%d %H:%M:%S")
    Variable syntax

    I realized that dbaccess is spawning the default shell of the user (be it informix or myself).  And each invocation of csh runs .cshrc, which has a bunch of stty commands.  These barf because, in  my script, the STDIN to dbaccess is a pipe.  Hence the stty errors.  I can live with this.  But what about the "variable syntax" errors?

    At first I went googling for a csh equivalent to the $(command) syntax. But since Google flooded me with useless solutions to different problems, I came up with a workaround in the sql script:

    !printf "Delete from table yutz at ";date +"%Y-%m-%d %H:%M:%S"    -- Table name changed, of course

    Note: No \n in the printf command.  Thus, I get this in the output:

    stty: : No such device or address
    stty: : No such device or address
    stty: : No such device or address
    stty: : No such device or address
    Delete from table yutz at 2026-09-22 12:36:08

    BTW, if I redirect 2>/dev/null, the date does not show up either.

    As to how to spawn a csh instance without executing the .cshrc (and getting those stty errors)? That is not an informix issue.  But if a csh expert on this forum chooses to give me a hand with a easy way to skip the .cshrc, I tip my yarmulka to you. ;-)

    I hope it's at least been an interesting read.



    ------------------------------
    +-----------------------------------------------------------+
    | I am pleased to report that I had no problems today. |
    | I had only issues, opportunities, challenges and valuable |
    | learning experiences. |
    +------------------------------------------ Jacob S --------+
    ------------------------------


  • 2.  RE: Error "Variable syntax" on shell command within SQL script

    Posted an hour ago
    Jacob,

    Why not do this?

    SELECT "Delete from table yutz at
     " || CURRENT YEAR TO SECOND FROM sysmaster:sysdual;

    To get you the output you are looking for without spawning a shell.

    That is what I have done in the past.






  • 3.  RE: Error "Variable syntax" on shell command within SQL script

    Posted 16 minutes ago
    David suggested:
    SELECT "Delete from table yutz at " || CURRENT YEAR TO SECOND FROM sysmaster:sysdual;

    David, That is SO beautiful and simple.  And I just flattened my forehead! ��‍♂️
    Too bad Windows does not supply an emoji of someone tipping his hat, let alone a yarmulka. ��

    • Jacob S





  • 4.  RE: Error "Variable syntax" on shell command within SQL script

    Posted 18 minutes ago

    Jacob:

    I agree with David, just use SELECT. Also, when I tested your echo command, it works for me:


    > !echo Delete from table yutz at $(date +"%Y-%m-%d %H:%M:%S")
    Delete from table yutz at 2026-09-22 14:56:35
    > select "Delete from table yutz at " || current year to second;


    (expression)                                                       

    Delete from table yutz at 2026-09-22 14:57:21                    
                   

    Art



    ------------------------------
    Art S. Kagel, President and Principal Consultant
    ASK Database Management Corp.
    www.askdbmgt.com
    ------------------------------