shell

How can I tell if a makefile is being run from an interactive shell?

两盒软妹~` 提交于 2021-02-18 10:41:08
问题 I have a makefile which runs commands that can take a while. I'd like those commands to be chatty if the build is initiated from an interactive shell but quieter if not (specifically, by cron). Something along the lines of (pseudocode): foo_opts = -a -b -c if (make was invoked from an interactive shell): foo_opts += --verbose all: bar baz foo $(foo_opts) This is GNU make. If the specifics of what I'm doing matter, I can edit the question. 回答1: It isn't strictly determining whether it is

How to access mysql database using shell script?

元气小坏坏 提交于 2021-02-18 10:38:45
问题 Is there a way I can access MySQL database using shell script? want to do some selects and some inserts on multiple tables? It will be great if you can give some sample code as I am new to scripting. 回答1: This link seems to have the information you want. http://www.cyberciti.biz/faq/using-mysql-in-shell-scripts/ mysql -u user -p dbnane 回答2: try this #!/bin/bash echo "show all tables" mysql -uroot -p'password' dbname<<EOFMYSQL show tables; EOFMYSQL echo "Count of all records" mysql -uroot -p

executing a script which runs even if i log off

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-18 08:23:08
问题 So, I have a long running script (of order few days) say execute.sh which I am planning to execute on a server on which I have a user account... Now, I want to execute this script so that it runs forever even if I logoff or disconnect from the server?? How do i do that? THanks 回答1: You have a couple of choices. The most basic would be to use nohup : nohup ./execute.sh nohup executes the command as a child process and detaches from terminal and continues running if it receives SIGHUP . This

Difference in pipe and file redirection - BASH

独自空忆成欢 提交于 2021-02-18 08:10:29
问题 Redirection is used to redirect stdout/stdin/stderr! Ex: ls > log.txt. Pipes are used to give the output of a command as input to another command. Ex: ls | grep file.txt Why exactly are these two operators doing the same thing? Why not just write ls > grep to pass the output through, isn't this just a kind of redirection also? I realize Linux is "Do one thing and do it well", so there has to be more of a logical reason that I'm missing. 回答1: You do need a differentiating syntax feature - and

Convert csv to html table using

眉间皱痕 提交于 2021-02-18 07:31:24
问题 How can I convert a CSV file into html table? I got a csv file with comma "," and I want this file to convert to Html table. 回答1: OK, you really want it only in bash? Mission accomplished. cat > input.csv a,b,c d,e,f g,h,i echo "<table>" ; while read INPUT ; do echo "<tr><td>${INPUT//,/</td><td>}</td></tr>" ; done < input.csv ; echo "</table>" <table> <tr><td>a</td><td>b</td><td>c</td></tr> <tr><td>d</td><td>e</td><td>f</td></tr> <tr><td>g</td><td>h</td><td>i</td></tr> </table> My first try

BASH scripting: n-th parameter of $@ when the index is a variable?

ぐ巨炮叔叔 提交于 2021-02-18 04:47:06
问题 I want to retrieve the n-th parameter of $@ (the list of command line parameters passed to the script), where n is stored in a variable. I tried ${$n}. For example, I want to get the 2nd command line parameter of an invocation: ./my_script.sh alpha beta gamma And the index should not be explicit but stored in a variable n. Sourcecode: n=2 echo ${$n} I would expect the output to be "beta", but I get the error: ./my_script.sh: line 2: ${$n}: bad substitution What am I doing wrong? 回答1: Try this

Merge Multiple .sql Table Dump Files Into A Single File

主宰稳场 提交于 2021-02-17 22:03:13
问题 Suppose I have database A and Table b. Given multiple .sql files b1,b2,...,bn each of which corresponds to a mutually exclusive table dump of b how would I go about combining all files b1,b2,...,bn into a single .sql table file? Or how would I combine the import of the individual files into a single table? 回答1: There are no special tools to do this. You can simply concatenate the files: $ cat b1.sql b2.sql b3.sql > b_all.sql Except that the typical content of these .sql files is a DROP TABLE,

How to configure 'less' to show formatted markdown files?

試著忘記壹切 提交于 2021-02-17 21:38:44
问题 I would like to have less display *.md markdown files with some formatting -- like I know less can, for manpages, etc. I am running Ubuntu 12.04. I am as far as putting a user defined filter into .lessfilter : #!/bin/sh case "$1" in *.md) fn=/tmp/$1.$$.html markdown "$1" | html2txt > $fn ### LOSES FORMATTING cat $fn ### TO STDOUT??? ;; *) # We don't handle this format exit 1 esac # No further processing by lesspipe necessary exit 0 So, the main questions are: How can I pass some basic

How to configure 'less' to show formatted markdown files?

廉价感情. 提交于 2021-02-17 21:37:46
问题 I would like to have less display *.md markdown files with some formatting -- like I know less can, for manpages, etc. I am running Ubuntu 12.04. I am as far as putting a user defined filter into .lessfilter : #!/bin/sh case "$1" in *.md) fn=/tmp/$1.$$.html markdown "$1" | html2txt > $fn ### LOSES FORMATTING cat $fn ### TO STDOUT??? ;; *) # We don't handle this format exit 1 esac # No further processing by lesspipe necessary exit 0 So, the main questions are: How can I pass some basic

ZOC Terminal:text has been cut halfway down the page

限于喜欢 提交于 2021-02-17 06:16:05
问题 I work with ZOC terminal installed at windows 7 in order to communicate with device that has Linux operating system zoc picture. The communication via terminal works great but recently the text has been cut halfway down the page. attached picture . 回答1: The picture shows 24 lines. You can get this behavior if your terminal description sets scrolling margins to 24 lines — as some might do, when initializing the terminal if the application assumes that the screen has 24 lines. Since ZOC could