0

I have a file test.sh in which i have a query which gives me the count of total records in the table, as shown below:

Query:

echo db2 -x "select count(*) from testable”

Now I want to assign the whatever value it returns after executing it to the variable as totalRecords using the Unix Shell Script.

1 Answer 1

3
#!/bin/bash

cnt=`db2 -x "select count(*) from syscat.tables" `

echo "Counter is:  ${cnt}"

Counter is: 474

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. Can i use this counter into some other files? If yes then how?
yes - you'd have to do a similar process of capturing the output with `` OR persist the value to a temp file and read the value into the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.