任何人都可以告诉我如何从命令行返回变量中的程序输出吗?
var = ./a.out params
Run Code Online (Sandbox Code Playgroud)
我试图从命令行运行它时将程序的输出变为变量.
我写了一个程序,让用户输入一个字符.如果角色是元音,什么都不做; 如果角色是辅音,请找到字母表中最接近的元音.有没有简单的方法来做到这一点?
这就是我现在所拥有的:
char input, output;
cin >> input;
if (input == 'b'){ output = 'a'; }
else if (input == 'c'){ output = 'a'; }
else if (input == 'd'){ output = 'e'; }
else if (input == 'f'){ output = 'e'; }
else if (input == 'g'){ output = 'e'; }
else if (input == 'h'){ output = 'i'; }
else if (input == 'j'){ output = 'i'; }
else if (input == 'k'){ output = 'i'; } …Run Code Online (Sandbox Code Playgroud) 我有一个字符串,我需要使用 shell 脚本将其中的“,”替换为“\,”。我以为我可以sed用来做到这一点,但没有运气。
我想在我的应用程序中集成角度进度指令.
我发现进度条指令解决了目的,但我无法改变进度条的颜色.我想为进度条提供自定义颜色.
有没有人对此有任何想法?
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.0.js"></script>
<script src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="ProgressDemoCtrl">
<h3>Static</h3>
<div class="row">
<div class="col-sm-4"><progressbar value="55"></progressbar></div>
<div class="col-sm-4"><progressbar class="progress-striped" value="22" type="warning">22%</progressbar></div>
<div class="col-sm-4"><progressbar class="progress-striped active" max="200" value="166" type="danger"><i>166 / 200</i></progressbar></div>
</div>
<hr />
<h3>Dynamic <button class="btn btn-sm btn-primary" type="button" ng-click="random()">Randomize</button></h3>
<progressbar max="max" value="dynamic"><span style="color:black; white-space:nowrap;">{{dynamic}} / {{max}}</span></progressbar>
<small><em>No animation</em></small>
<progressbar animate="false" value="dynamic" type="success"><b>{{dynamic}}%</b></progressbar>
<small><em>Object (changes type based on value)</em></small>
<progressbar class="progress-striped active" value="dynamic" type="{{type}}">{{type}} <i ng-show="showWarning">!!! Watch out !!!</i></progressbar> …Run Code Online (Sandbox Code Playgroud) 我想将字符串回显到/etc/hosts文件中。该字符串存储在名为 的变量中$myString。
当我运行以下代码时,回显为空:
finalString="Hello\nWorld"
sudo bash -c 'echo -e "$finalString"'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我想做一些像这些语句中的任何一个,这可能像bash,但收到错误:
if ! prog ...
....
Run Code Online (Sandbox Code Playgroud)
错误: fish: Unknown command '! prog ...'
if test ! prog ...
....
Run Code Online (Sandbox Code Playgroud)
错误: test: Expected a combining operator like '-a' at index 2
我正在尝试一些测试,在 shell 脚本中如下所示:
line="100:xx"
echo "$line" | grep -Po \\d+
Run Code Online (Sandbox Code Playgroud)
结果:100
但,
line="100:xx"
echo `echo "$line" | grep -Po \\d+`
Run Code Online (Sandbox Code Playgroud)
结果为空
为什么?
对于负载测试,我想在我用jmeter运行测试之前随机化我的测试值.为此,我想使用这个bash脚本:
#! /bin/bash
cat data.dsv | shuf > randomdata.dsv
Run Code Online (Sandbox Code Playgroud)
这应该用jmeter执行.我尝试使用BeanShell Sampler和这个命令(我使用这个命令总是找到正确的文件,无论我想在哪台机器上执行它):
execute(${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}random.sh)
Run Code Online (Sandbox Code Playgroud)
但我总是收到此错误消息:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval In file: inline evaluation of: ``execute(/home/user/git/path/'' Encountered "( /" at line 1, column 8.
Run Code Online (Sandbox Code Playgroud)
任何想法做什么或有什么最好的做法我还没找到?
我有两个输出文件:
FILE-A:
TOM
JACK
AILEY
BORG
ROSE
ELI
Run Code Online (Sandbox Code Playgroud)
文件-B 内容:
TOM
ELI
Run Code Online (Sandbox Code Playgroud)
我想从File-A中删除FILE-B中列出的任何内容.
FILE-C(结果文件):
JACK
AILEY
BORG
ROSE
Run Code Online (Sandbox Code Playgroud)
我想我需要一份while r for i声明.有人可以帮我弄这个吗?我需要cat阅读FILE-A并且对于FILE-B中的每一行我需要从FILE-A中删除它.
我应该使用什么命令?
我是shell脚本和sed命令的新手.
以下sed命令在Solaris中有效但在Linux中出错:
sed -n 's/^[a-zA-z0-9][a-zA-z0-9]*[ ][ ]*\([0-9][0-9]*\).*[/]dir1[/]subdir1\).*/\2:\1/p'
Run Code Online (Sandbox Code Playgroud)
错误是:
sed: -e expression #1, char 79: Invalid range end
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它会给出无效的范围结束错误.