RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

问题[shell]

Martin Hope
Fedor March
Asked: 2022-08-21 16:16:29 +0000 UTC

在脚本确认中添加默认响应

  • 1

有一个设计:

read -p "Are you sure? " 

可以添加一个默认响应,最终它看起来像这样:

你确定吗?是的

在这种情况下,用户只需按回车键

bash shell
  • 1 个回答
  • 27 Views
Martin Hope
alex2020
Asked: 2022-05-08 00:39:07 +0000 UTC

使用 awk、perl 或另一种单线法减去字符串中的时间

  • 1

你能告诉我如何使用单线解决以下问题吗?

目标是从当前行的第一列中减去前一行的第一列的值,并将其放在当前行之前。

有一个文件,如:

$ cat blabla 
13:06:27.578195 blablabla
13:06:27.578243 bla bla
13:06:27.578271 bla
13:06:27.578337 zzz
13:06:27.578372 zzz zzz zzz
13:06:27.578372 zzz zzz zzz
13:07:02.224100 aaa bbb ccc

有必要在一行中使用任何命令来获取表单的输出:

0 13:06:27.578195 blablabla
0.000048 13:06:27.578243 bla bla
0.000028 13:06:27.578271 bla
0.000066 13:06:27.578337 zzz
0.000035 13:06:27.578372 zzz zzz zzz
34,645728 13:07:02.224100 aaa bbb ccc

似乎这可以用 来完成awk,但我没有成功。

shell
  • 2 个回答
  • 10 Views
Martin Hope
Vlad
Asked: 2020-02-28 17:08:09 +0000 UTC

在文件的最后一行中查找子字符串

  • 1

我正在编写一个脚本,从所有给定掩码的文件中确定文件的最后一行是否是“不正确的卷”

#!/bin/sh

f=`find -name \*-volume.log`

for file in $f
do
out = `tail -n 1 ${file#*./}`
echo $out
if [$out = "Incorrect volume" ]
then
echo "Privet"
fi
echo ${file#*./}
done

我写了这段代码,但由于某种原因它没有读取 out 变量,也不接受字符串比较条件。帮助理解错误。

shell
  • 2 个回答
  • 10 Views
Martin Hope
Adollo
Asked: 2020-07-18 20:20:20 +0000 UTC

通过 RScript.exe 运行脚本时,R shell() 函数未将结果保存到向量?

  • 1

脚本“wget_test.R”:

print(paste0('OUT:', shell("bash -c 'wget https://www.ft.com -O out.html'", intern = TRUE)))

我在 R 控制台中运行:

 [1] "OUT:Will not apply HSTS. The HSTS database must be a regular and non-world-writable file."
 [2] "OUT:ERROR: could not open HSTS store at '/home/adollo/.wget-hsts'. HSTS will be disabled."
 [3] "OUT:--2019-07-18 14:58:46--  https://www.ft.com/"                                         
 [4] "OUT:Resolving www.ft.com (www.ft.com)... 151.101.246.109"                                 
 [5] "OUT:Connecting to www.ft.com (www.ft.com)|151.101.246.109|:443... connected."             
 [6] "OUT:HTTP request sent, awaiting response... 200 OK"                                       
 [7] "OUT:Length: 446829 (436K) [text/html]"                                                    
 [8] "OUT:Saving to: вЂ\u0098out.html’"                                                       
 [9] "OUT:"                                                                                     
[10] "OUT:     0K .......... .......... .......... .......... .......... 11%  851K 0s"          
[11] "OUT:    50K .......... .......... .......... .......... .......... 22% 1.65M 0s"          
[12] "OUT:   100K .......... .......... .......... .......... .......... 34% 47.7M 0s"          
[13] "OUT:   150K .......... .......... .......... .......... .......... 45% 51.5M 0s"          
[14] "OUT:   200K .......... .......... .......... .......... .......... 57%  636K 0s"          
[15] "OUT:   250K .......... .......... .......... .......... .......... 68% 36.9M 0s"          
[16] "OUT:   300K .......... .......... .......... .......... .......... 80% 47.7M 0s"          
[17] "OUT:   350K .......... .......... .......... .......... .......... 91% 51.0M 0s"          
[18] "OUT:   400K .......... .......... .......... ......               100% 47.2M=0.2s"        
[19] "OUT:"                                                                                     
[20] "OUT:2019-07-18 14:58:46 (2.46 MB/s) - вЂ\u0098out.html’ saved [446829/446829]"          
[21] "OUT:"

我在 Windows 终端中运行“RScript wget_test.R”:

Will not apply HSTS. The HSTS database must be a regular and non-world-writable file.
ERROR: could not open HSTS store at '/home/adollo/.wget-hsts'. HSTS will be disabled.
--2019-07-18 14:59:03--  https://www.ft.com/
Resolving www.ft.com (www.ft.com)... 151.101.246.109
Connecting to www.ft.com (www.ft.com)|151.101.246.109|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 446759 (436K) [text/html]
Saving to: ‘out.html’

out.html                      100%[=================================================>] 436.29K  --.-KB/s    in 0.1s

2019-07-18 14:59:03 (3.07 MB/s) - ‘out.html’ saved [446759/446759]

[1] "OUT:"

我也试过系统功能 - 结果是一样的。

结果差异的原因可能是什么?

R 控制台中的 sessionInfo():

R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=Russian_Russia.1251  LC_CTYPE=Russian_Russia.1251    LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C                   
[5] LC_TIME=Russian_Russia.1251    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rvest_0.3.4 xml2_1.2.0 

loaded via a namespace (and not attached):
 [1] httr_1.4.0     compiler_3.6.0 selectr_0.4-1  magrittr_1.5   R6_2.4.0       tools_3.6.0    curl_3.3       Rcpp_1.0.1     stringi_1.4.3 
[10] stringr_1.4.0 

sessionInfo() 通过 RScript.exe:

R version 3.6.0 (2019-04-26) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale: [1] LC_COLLATE=Russian_Russia.1251  LC_CTYPE=Russian_Russia.1251 [3] LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C [5] LC_TIME=Russian_Russia.1251

attached base packages: [1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached): [1] compiler_3.6.0
shell
  • 1 个回答
  • 10 Views
Martin Hope
ks_on_v
Asked: 2020-06-24 23:55:27 +0000 UTC

在 Scala 中运行 shell 命令

  • 3

您需要运行控制台命令来获取文件大小:

hadoop fs -du some/path

并将结果存储在变量中。如何在 Scala 中做到这一点?

shell
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5