sh

Edit text format with shell script

戏子无情 提交于 2019-12-10 17:34:56
问题 I am trying to make a script for text editing. In this case I have a text file named text.csv, which reads: first;48548a;48954a,48594B second;58757a;5875b third;58756a;58576b;5867d;56894d;45864a I want to make text format to like this: first;48548a first;48954a first;48594B second;58757a second;5875b third;58756a third;58576b third;5867d third;56894d third;45864a What is command should I use to make this happen? 回答1: I'd do this in awk. Assuming your first line should have a ; instead of a ,

Is unsetting global variables defined in a script good practice?

主宰稳场 提交于 2019-12-10 17:19:02
问题 Is it considered good practice, when writing sh scripts, to unset all previously defined global variables at the end of the script? If for example, I execute my script myscript using the . (source) builtin, like this . myscript after executing the script the shell is poluted with the variables defined in the script. This seems really bad (especially if used by other people). If I could, I would get rid of globals in sh (or bash) altogether but more often then not they are the least worst

cannot create /dev/stdout: No such device or address

做~自己de王妃 提交于 2019-12-10 17:15:00
问题 I'm want to run a shell command via node and capture the result of stdout. My script works fine on OSX, but not on Ubuntu. I've simplified the problem and script to the following node script: var execSync = require('child_process').execSync, result = execSync('echo "hello world" >> /dev/stdout'); // Do something with result Results in: /bin/sh: 1: cannot create /dev/stdout: No such device or address I have tried replacing /dev/stdout with /dev/fd/1 I have tried changing the shell to bash...

Using getopts within user-defined-function in bourne shell

爷,独闯天下 提交于 2019-12-10 16:54:45
问题 Is it possible to pass command line arguments into a function from within a bourne script, in order to allow getopts to process them. The rest of my script is nicely packed into functions, but it's starting to look like I'll have to move the argument processing into the main logic. The following is how it's written now, but it doesn't work: processArgs() { while getopts j:f: arg do echo "${arg} -- ${OPTARG}" case "${arg}" in j) if [ -z "${filename}" ]; then job_number=$OPTARG else echo

Compiling and Running java in Unix ( coming from Windows )

試著忘記壹切 提交于 2019-12-10 16:19:41
问题 Ok, this is working on windows. My Java app is running and functioning normally javac -classpath .;ojdbc14.jar -g foo.java java -classpath .;ojdbc14.jar foo However, when I do the same thing on Unix I get this error: ojdbc14.jar: not found What am I doing wrong? I know the ";" is telling my shell that ojdbc14.jar is a new command, but I'm not sure how to fix this. 回答1: Use a colon (":") instead of a semicolon (";"). See Setting the class path (Solaris and Linux) vs Setting the class path

How to run sh file from another sh file

北慕城南 提交于 2019-12-10 15:48:53
问题 I have a shell script file for monitoring my application, this script will be executed every 10 min by setting cron job. I would like to some more script files which are related to monitoring should be executed along with master file. So I would like to include my scripts to master file. How to run those sh file from master sh file 回答1: Take a look at this. If you want to run a script you can use: ./yourscript.sh If your script has a loop, use: ./yourscript.sh& If you want to get the console

Pass shell-escaped string of arguments to a subcommand in Bourne shell

若如初见. 提交于 2019-12-10 15:37:54
问题 Say I have a command I want to run ( cmd ) and a variable containing the arguments I want to pass to the function (something like --foo 'bar baz' qux ). Like so: #!/bin/sh command=cmd args="--foo 'bar baz' qux" The arguments contain quotes, like the ones shown above, that group together an argument containing a space. I'd then like to run the command: $command $args This, of course, results in running the command with four arguments: --foo , 'bar , baz' , and qux . The alternative I'm used to

Return value from system() when using SIGINT default handler

£可爱£侵袭症+ 提交于 2019-12-10 15:29:15
问题 I am experiencing some strange return values from system() when a child process receives a SIGINT from the terminal. To explain, from a Perl script parent.pl I used system() to run another Perl script as a child process, but I also needed to run the child through the shell, so I used the system 'sh', '-c', ... form.. So the parent of the child became the sh process and the parent of the sh process became parent.pl . Also, to avoid having the sh process receiving the SIGINT signal, I trapped

How to run R codes inside shell script?

自作多情 提交于 2019-12-10 13:58:47
问题 I have a R file ( myfile.R). I want to run it using a shell script. How Can I do that? I tried this: #! /bin/bash Rscript myfile.R but it gives me this error: Rscript: command not found I also tried this: #! /bin/bash R --not-save-- < myfile.R It also gives this error: R : command not found What is the best way to do that? 回答1: The idea is to not write a shell but to write an R script. That is what Rscript is for, and our littler package offered /usr/bin/r even before that. So just do #!/usr

truncate table via command line in Linux

喜你入骨 提交于 2019-12-10 12:53:41
问题 I want to truncate one of my db table using mysqldump command so that I can place that command in sh file for executing it on daily basis. Do any one know about this command? Thanks in advance 回答1: You can use mysql command line client to do it mysql -h dbserver_hostname -e "truncate table schema_name.table_name" 回答2: localhost=hostname root=username ''=password demo=db name language=table name #to truncate a table from database mysql -h localhost -u root -p'' demo -e "truncate table demo