1

I have a chain of commands that can execute all at once, however I wish to put it inside of a bash script. The problem is that I have no clue how to. My command is like so:

/usr/bin/sort -n db | /usr/bin/awk -F: '{print $1; print $2}' | db5.1_load -T -t hash newdb

How can I convert the above into a bash script?

5
  • 1
    Stick it in a file, chmod +x ? Commented Mar 31, 2013 at 2:32
  • I tried this, and it did not work. Commented Mar 31, 2013 at 2:36
  • 1
    What kind of errors did you get, then? Commented Mar 31, 2013 at 2:37
  • I forgot to include the path to sort and awk. My apologies guys. Commented Mar 31, 2013 at 2:39
  • You may be missing the Unix shebang on the first line, see my answer below Commented Mar 31, 2013 at 2:46

1 Answer 1

4

This should normally be as simple as putting the shell command into a text file, and putting the Unix shebang on the first line of the file, which defines which program to use to run the script (in this case, /bin/bash). So this would look like:

#!/bin/bash

/usr/bin/sort -n db | /usr/bin/awk -F: '{print $1; print $2}' | db5.1_load -T -t hash newdb
Sign up to request clarification or add additional context in comments.

1 Comment

Just be aware that if you execute that script on Solaris then it will fail because /usr/bin/awk on Solaris is old, broken awk which does not support the -F option. On Solaris us /usr/xpg4/bin/awk or nawk.

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.