sh

special meaning of ^ (caret) in solaris (bourne?) sh?

北城余情 提交于 2019-12-24 01:03:06
问题 On Solaris, it appears I need to single quote 'a match the beginning of line' expression: > sh $ echo offset 0.000000 2>&1 | grep ^offset | tail -1 offset: not found $ Usage: grep [-c|-l|-q] [-bhinsvwx] pattern_list [file ...] grep [-c|-l|-q] [-bhinsvwx] [-e pattern_list]... [-f pattern_file]... [file...] grep -E [-c|-l|-q] [-bhinsvx] pattern_list [file ...] grep -E [-c|-l|-q] [-bhinsvx] [-e pattern_list]... [-f pattern_file]... [file...] grep -F [-c|-l|-q] [-bhinsvx] pattern_list [file ...]

How can I treat the output of a command as a file?

醉酒当歌 提交于 2019-12-23 21:28:58
问题 The whiptail command has an option --textbox that has the following description: --textbox <file> <height> <width> The first option requires a file as input; I would like to use the output of a command in its place. It seems like this should be possible in bash - possibly with redirection? For the sake of the question, let's say I'd like to view the output of ls -l in a whiptail textbox. Update It looks like the marked answer does answer the question I asked, just not as regards to whiptail.

sh -c and process substitution [duplicate]

纵饮孤独 提交于 2019-12-23 17:53:15
问题 This question already has answers here : Difference between sh and bash (11 answers) Closed 3 years ago . In terminal (bash) the following works fine: cat <(echo "hello") But if I do: sh -c 'cat <(echo "hello")' I get sh: 1: Syntax error: "(" unexpected Can you explain the reason why? Btw, my overall aim is to write this command in a shell script: watch -n 1 'cat <(iptables -L INPUT) <(iptables -L FORWARD)' but it won't work, the reason seems to be the above problem. 回答1: sh is often dash not

filter a file with other file in bash

谁说我不能喝 提交于 2019-12-23 16:09:51
问题 i Have a file with numbers, for example: $cat file 31038467 32048169 33058564 34088662 35093964 31018168 31138061 31208369 31538163 31798862 and other for example with $cat file2 31208369 33058564 34088662 31538163 31038467 Then i need other file with lines that are in the first file but not in the second cat $output 35093964 31018168 31138061 31798862 32048169 My real file has 12'000.0000 of lines. Then how can i do it? 回答1: Is grep -f file2 -v -F -x file1 sufficient? NOTE1: Please specify

How can I display intermediate pipeline results for NUL-separated data?

流过昼夜 提交于 2019-12-23 15:39:58
问题 How can I combine the following two commands: find . -print0 | grep -z pattern | tr '\0' '\n' find . -print0 | grep -z pattern | xargs -0 my_command into a single pipeline? If I don't need NUL separators then I can do: find . | grep pattern | tee /dev/tty | xargs my_command I want to avoid using a temporary file like this: find . -print0 | grep -z pattern > tempfile cat tempfile | tr '\0' '\n' cat tempfile | xargs -0 my_command rm tempfile This question is a follow-up to these answers: 1)

how to echo a double backslash plus a variable (version number) like “\\hostname\release\1.02A01” by using sh?

本小妞迷上赌 提交于 2019-12-23 13:34:08
问题 I want to echo a Windows shared folder address to users in a Linux shell script, the address are strings like this: \\hostname\release\1.02A01. and the last string(1.02A01) is a version number, it's changed each time when I run the script. I tried something like this in sh (not bash ), but it doesn't work: version=$1 # version number are get from the parameter repository="\\\hostname\release\$version" echo $repository # I get this: \hostname\dir$version Here are the two errors: the double

run bash command from .NetCore with arguments

瘦欲@ 提交于 2019-12-23 09:53:34
问题 I am trying to run one .NetCore program from another. ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "sh"; psi.Arguments = "-c dotnet /home/myuser/PublishOutput/myprogram.dll"; psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; Process proc = new Process { StartInfo = psi }; proc.Start(); string error = proc.StandardError.ReadToEnd(); if (!string.IsNullOrEmpty(error)) return "error: " + error; string output = proc.StandardOutput

How to make expect command in expect program script to wait for exact string matching

随声附和 提交于 2019-12-23 09:46:59
问题 I want to know how to make expect command in expect script to wait for exact string to be matched before proceeding to next line in the script. Bourne shell (sh) script: #!/bin/sh #!/usr/bin/expect spawn ssh -Y localuser@lbblr-tirumala expect -exact "localuser@lbblr-tirumala's password: " # replace password with ur own passwd send "geomax45\r" # replace the prompt with ur own prompt expect "localuser@lbblr-tirumala:~$ " # run application send "./sample\r" expect "*Menu*\r 1. print hello world

OSTYPE not available in shell script

六眼飞鱼酱① 提交于 2019-12-23 07:56:25
问题 Currently I'm setting up a new system using the new Xubuntu trusty tahr. I'm not very familiar with shell scripting, but I have one which needs the OSTYPE environment variable to determine what to do. If I call echo $OSTYPE in the xfce-terminal I get succesfully linux-gnu . If I call following script I only get an empty line. #!/bin/sh echo $OSTYPE Am I missing something or is it maybe a problem of the new ubuntu? On another machine of mine it works with that script. But I don't know if

What does “2<&1” redirect do in Bourne shell?

柔情痞子 提交于 2019-12-23 07:28:37
问题 2>&1 redirect in Bourne shell takes the output sent to a file descriptor 2 (by default, standard error) and sends it instead to file descriptor 1 (by default a standard output). But what does 2<&1 redirect do? Does it send stderr to stdin? My theory was that it was sending stdin to stderr (e.g. same as 1>&2 ) but experimentally, that is NOT the case: $ perl -e 'print "OUT\n"; print STDERR "ERR\n"; \ while (<>) { print "IN WAS $_\n";}' \ > out3 2<&1 df $ cat out3 ERR OUT IN WAS df Note that