Skip to Content
avatar image
Former Member

Is there a way to pass an argument to an input file from a bash script? (ASE 12.5, 15.0, 15.3, 15.7)

Dear Support Team,

I would like to pass an argument (or more) from a bash script to an input file so I can use that parameter in my SQL code.

cat sybase.sh

#!/bin/bash

isql -S SERVER_NAME -U USER_NAME -P PASSWORD -i input.sql

cat input.sql

USE master

GO

SELECT COUNT(*) FROM <argument_from_bash_script>

GO

Is this possible somehow?

Thanks in advance.

Regards,

Laszlo

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jul 11, 2017 at 04:35 PM

    There are tons of ways to do this depending on your requirements, but the easiest (in this case) would probably be to use a here file, eg:

    #!/bin/bash
    
    my_input_table=$1
    
    isql -S SERVER_NAME -U USER_NAME -P PASSWORD<<-EOF
    select count(*) from ${my_input_table}
    go
    EOF

    You didn't mention your shell script's input format so the above should work for something like:

    $ ./my_script tempdb..mytable
    
    # or
    
    $ ./my_script myd.myowner.mytable
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 18, 2017 at 09:26 AM

    Thanks a lot Mark, it worked.

    Add comment
    10|10000 characters needed characters exceeded