I am constantly running commands like
nohup psql -d db -f foo1.sql >& foo1.out &
nohup psql -d db -f foo2.sql >& foo2.out &
I was wondering how to create a shellscript that takes as input the filename parameter like foo1.sql and runs the command above.
How do I write a script called test so that the command ./test foo1.sql will execute the command
nohup psql -d db -f foo1.sql >& foo1.out &
解决方案
Try this
#!/bin/bash
outputFile="$(echo $1 | cut -d\. -f 1).out"
nohup psql -d db -f "$1" >& "$outputFile" &
It's not called with ./test(foo1.sql) but ./test foo1.sql, as shown after the question was edited.