AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-65536

mrjayviper's questions

Martin Hope
mrjayviper
Asked: 2024-08-06 13:50:07 +0800 CST

bash 5.2.x + 三元运算符:如何在检查字符串变量是否为空时使用此组合?

  • 5

我努力了

#!/bin/bash

distro=""

myvar1=[[ -n "$distro" ]] && echo $distro || echo "debian"
myvar2=$((-n $distro ? $distro : "debian"))

这些是脚本的结果

./build.sh: line 5: -n: command not found
debian
./build.sh: line 6: -n  ?  : debian: expression expected (error token is ": debian")
bash
  • 1 个回答
  • 24 Views
Martin Hope
mrjayviper
Asked: 2022-02-05 19:03:10 +0800 CST

Fish 3.3.1 shell:如何否定字符串匹配的结果?

  • 0

如上。

基本上我想实现类似的东西

if not match then
  do these things
else
  do these other things
fi

谢谢

fish
  • 2 个回答
  • 97 Views
Martin Hope
mrjayviper
Asked: 2019-11-13 06:51:53 +0800 CST

如何读取键盘输入并将其分配给局部变量?

  • 3

我有这个非常简单的脚本:

#!/bin/bash

read local _test
echo "_test: $_test"

这是输出。

$ ./jltest.sh
sdfsdfs
_test: 

我希望变量_test仅是本地的。这可能吗?

bash
  • 1 个回答
  • 560 Views
Martin Hope
mrjayviper
Asked: 2019-10-17 05:36:01 +0800 CST

ZSH:如何转义以下命令(变量赋值)?

  • 1
_test=`shasum -a 256 my "file here.txt" | awk -F' ' '{print $1}'`

这按预期工作。但是我的强迫症想要使用类似的东西

_test="${my-command-here}"

但是由于 awk 部分中的单引号,我得到了一个错误的替换错误。

$ _test="${shasum -a 256 "my file here.txt" | awk -F' ' '{print $1}'}"
zsh: bad substitution
$ _test=${shasum -a 256 \"my file here.txt\" | awk -F\' \' \'{print $1}\'}
zsh: bad substitution

关于如何让它工作的任何想法?谢谢

zsh
  • 1 个回答
  • 358 Views
Martin Hope
mrjayviper
Asked: 2019-10-08 03:56:35 +0800 CST

如何在 ZSH 中循环选择文件扩展名?

  • 2

我正在寻找与此 BASH 构造等效的 ZSH:

for file in *.{abc,def,ghi}; do #loop through all files with the extensions .abc, .def and .ghi

我找不到 ZSH 的类似结构。或者也许没有?

zsh
  • 1 个回答
  • 812 Views
Martin Hope
mrjayviper
Asked: 2019-03-04 03:03:24 +0800 CST

zsh:如何根据另一个变量获取变量的值?

  • 5

我认为一个例子最能解释我需要什么

_v1="windows"

_v2_windows="/mnt/d"
_v2_osx="/Volumes/d"

echo $_v2_`echo $_v1`

我想回显的值,_v2_windows但_v1用于确定v2要获得两个 s 中的哪一个。

我知道可以使用case语句来解决问题,但我试图避免这种情况。

zsh variable
  • 2 个回答
  • 1695 Views
Martin Hope
mrjayviper
Asked: 2019-02-22 04:02:28 +0800 CST

"==" 逻辑运算符和 zsh 版本 5.7.x(使用 Homebrew 安装)

  • 3

使用此运算符时,我的脚本出现错误。我有一些在线文档,双等号应该可以工作。有任何想法吗?

Zsh 参考指南:http: //zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html

脚本:

#!/bin/zsh

if [ $_user == "root" ]; then
    echo "root"
else
    echo "not root"
fi

运行它:

$ ./script.sh
./script.sh:3: = not found
zsh osx
  • 3 个回答
  • 1409 Views
Martin Hope
mrjayviper
Asked: 2018-11-22 16:55:19 +0800 CST

查找并替换子字符串并更改为大写

  • 0

我认为最好用一个例子来完成

我的文件内容

name="apple" parameter1="value1" parameter2="value2";
name="orange" parameter1="value1" parameter2="value2";
name="tea" parameter1="value1" parameter2="value2";
name="whatever" parameter1="value1" parameter2="value2";

我想将 apple/orange/tea/whatever 转换为大写并将其保存回同一文件或新文件。

关于如何完成的任何想法?谢谢

编辑:

  • 文件中的所有内容都包含在内,但目前没有任何行会被排除。
  • 此外,文本“名称”周围没有引号。如上所述保存。
find string
  • 1 个回答
  • 120 Views
Martin Hope
mrjayviper
Asked: 2018-06-03 04:17:36 +0800 CST

如何使用 sed+regex 在文本文件的指定位置插入一行?

  • 1

我有一个类似于下面示例的文本文件。

我要插入

<string>insert-me</string>

在指示的行。

我该怎么做?我尝试了与此类似的变体:

sed "/s/<key>first</key>/\n        <array>/\n/test/g" test.txt

而且我不断收到“替代命令中的错误标志”错误。

谢谢

示例文本文件:

<record>
    <key>first</key>
    <array>
        --I want to insert the line here--
        <string>hello</string>
        <string>world</string>
        </array>
</record>
<record>
    <key>second</key>
    <array>
        <string>its</string>
        <string>me</string>
        <string>again</string>
        <string>hello</string>
        <string>world</string>
        <string>again</string>
    </array>
</record>
regular-expression sed
  • 1 个回答
  • 237 Views
Martin Hope
mrjayviper
Asked: 2018-06-02 17:56:19 +0800 CST

bash/bourne 中是否有“in”运算符?

  • 19

我正在寻找一个像这样工作的“in”运算符:

if [ "$1" in ("cat","dog","mouse") ]; then
    echo "dollar 1 is either a cat or a dog or a mouse"
fi

与使用多个“或”测试相比,这显然是一个更短的语句。

bash shell-script
  • 5 个回答
  • 13567 Views
Martin Hope
mrjayviper
Asked: 2018-04-08 04:22:15 +0800 CST

使用 mount 命令挂载 samba 共享时如何使用凭证文件?

  • 11

所以我经常使用这个命令来挂载一个 Samba 共享。

mount -t cifs //ip/share /mnt/backups -o username=user,password=pwd,domain=domain

我想使用凭据文件(具有 600 权限)而不是输入用户名/密码。

任何想法如何做到这一点?我环顾四周,发现的唯一示例是使用凭据文件,如果我想使用 /etc/fstab 自动挂载 Samba 共享。

谢谢

mount samba
  • 1 个回答
  • 44947 Views
Martin Hope
mrjayviper
Asked: 2017-11-29 04:44:57 +0800 CST

Krename:如何为每个文件夹重新编号?

  • 0

我有 4 个文件夹,每个文件夹 3 个。重命名操作后,我会有

folder1
  - file1.txt
  - file2.txt
  - file3.txt
folder2
  - file1.txt
  - file2.txt
  - file3.txt
and so on.

当我尝试使用 [$dirname]#### 时,我得到

folder1
  - file1.txt
  - file2.txt
  - file3.txt
folder2
  - file4.txt
  - file5.txt
  - file6.txt
and so on.

知道它是怎么做的吗?谢谢

rename kde
  • 1 个回答
  • 280 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve