English 中文(简体)
2. 改用面目光输出
原标题:Redirect bash output to dynamic file name

I m writing a bash script that will (hopefully) redirect to a file whose name is generated dynamically, based on the the first argument given to the script, prepended to the some string. The name of the script is ./buildcsvs.

Here s what the code looks like now, without the dynamic file names

#!/bin/bash
mdb-export 2011ROXBURY.mdb TEAM > team.csv

在这里,我喜欢这样说来。

./buildcsvs roxbury

产出

roxburyteam.csv

“1美元”是文字的首批动力,档案名称被像一类的东西所定义。

"%steam" % $1

你们是否有任何想法? 谢谢。

最佳回答

1美元与“team.csv”。

#!/bin/bash
mdb-export 2011ROXBURY.mdb TEAM > "${1}team.csv"

如果他们不向书写人提出论据,将写上“team.csv”。

问题回答

你可以通过<条码>1或其他类似内容提及一种立场论点。 我写了以下微薄的测试文字,以证明如何做:

$ cat buildcsv 
#!/bin/bash
echo foo > $1.csv
$ ./buildcsv roxbury
$ ./buildcsv sarnold
$ ls -l roxbury.csv sarnold.csv 
-rw-rw-r-- 1 sarnold sarnold 4 May 12 17:32 roxbury.csv
-rw-rw-r-- 1 sarnold sarnold 4 May 12 17:32 sarnold.csv

Try replacing team.csv with $1.csv.

请注意,未经争辩即可操作该书状,然后制作 empt/em>。 编号.csv。 如果你想处理,你必须计算使用<代码>的编号<#>/code>的论点。 我也赞扬:

$ cat buildcsv 
#!/bin/bash
(( $# != 1 )) && echo Need an argument && exit 1
echo foo > $1.csv




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签