Skip to Content
0

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)

Jul 11, 2017 at 02:14 PM

51

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Mark A Parsons Jul 11, 2017 at 04:35 PM
2

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
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jul 18, 2017 at 09:26 AM
0

Thanks a lot Mark, it worked.

Share
10 |10000 characters needed characters left characters exceeded