我有一个 Makefile,它有一个变量,如果变量未设置或设置但具有空值,则该变量需要具有默认值。
我怎样才能做到这一点?
我需要这个,因为我在 shell 脚本中调用 make 并且 makefile 所需的值可以作为 $1 从 shell 传递。并将其传递给 makefile,我必须将其设置在 bash-script 中。
想法:(不优雅)在 bash 脚本内部,可以检查变量是否已设置但具有空值,在这种情况下可以取消设置。
注意:如果变量未在终端中定义,以下将不起作用,因为它们是在 bash 脚本中设置的。
dSourceP?=$(shell pwd)
Source?=$(notdir $(wildcard $(dSourceP)/*.md))
Run Code Online (Sandbox Code Playgroud)
make all dSourceP="${1}" Source="${2}"
Run Code Online (Sandbox Code Playgroud)
bash ./MyScript.sh
bash ./MyScript.sh /home/nikhil/MyDocs
bash ./MyScript.sh /home/nikhil/MyDocs index.md
Run Code Online (Sandbox Code Playgroud) 为什么 cron 需要 MTA 进行日志记录?这有什么特别的好处吗?为什么它不能像大多数其他实用程序一样创建日志文件?
操作系统:Ubuntu 20.04.3
$ \cat /home/nikhil/.config/systemd/user/Festival.service
[Unit]
Description=Festival Service
[Service]
ExecStart=/usr/bin/festival --server
Restart=on-failure
RestartSec=10
SyslogIdentifier=FestivalService
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
我这样做了systemctl --user enable Festival.service,重新启动了我的系统。但节日服务器没有启动。只有当我手动执行时systemctl --user start Festival.service,它才会启动。
您能否告诉我,为什么用户服务不能与 一起使用multi-user.target,而它应该在每次启动时都起作用?
我想找到所有子文件夹,其中包含具有相同名称(和扩展名.md)的降价文件。
例如:我想查找以下子文件夹:
Apple/Banana/Orange #Apple/Banana/Orange/Orange.md exists
Apple/Banana #Apple/Banana/Banana.md exists
Apple/Banana/Papaya #Apple/Banana/Papaya/Papaya.md exists
Run Code Online (Sandbox Code Playgroud)
有什么建议?
可以使用以下代码测试问题的解决方案:
#!/usr/bin/env bash
# - goal: "Test"
# - author: Nikhil Agarwal
# - date: Wednesday, August 07, 2019
# - status: P T' (P: Prototyping, T: Tested)
# - usage: ./Test.sh
# - include:
# 1.
# - refer:
# 1. [directory - Find only those folders that contain a File with the same name as the Folder - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/534190/find-only-those-folders-that-contain-a-file-with-the-same-name-as-the-folder) …Run Code Online (Sandbox Code Playgroud) 当.ONESHELL不使用生成文件执行在一个单独的外壳的每个外壳命令。这有什么好处?为什么makefile 不使用相同的shell?
当我执行以下脚本时
#!/usr/bin/env bash
main() {
shopt -s expand_aliases
alias Hi='echo "Hi from alias"'
Hi # Should Execute the alias
\Hi # Should Execute the function
"Hi"
}
function Hi() {
echo "Hi from function"
}
main "$@"
Run Code Online (Sandbox Code Playgroud)
它第一次执行函数,然后总是作为别名执行:
$ . Sample.sh
Hi from function
Hi from function
Hi from function
$ . Sample.sh
Hi from alias
Hi from function
Hi from function
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
在以下情况下不会发生这种情况
#!/usr/bin/env bash
function Hi() {
echo "Hi from function"
}
shopt -s expand_aliases
alias Hi='echo "Hi …Run Code Online (Sandbox Code Playgroud) 我做了如下:
$ gsettings get org.gnome.desktop.session idle-delay
uint32 300
$ gsettings set org.gnome.desktop.session idle-delay 80
$ gsettings get org.gnome.desktop.session idle-delay
uint32 80
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时:dconf dump /org/gnome/,我看到如下:
$ gsettings get org.gnome.desktop.session idle-delay
uint32 300
$ gsettings set org.gnome.desktop.session idle-delay 80
$ gsettings get org.gnome.desktop.session idle-delay
uint32 80
Run Code Online (Sandbox Code Playgroud)
观察:dconf dump显示真实值,但gsettings显示新值,但与 dconf-editor 显示的值不同
$ dconf dump /org/gnome/desktop/session
[/]
idle-delay=uint32 60
Run Code Online (Sandbox Code Playgroud)
观察:dconf dump显示真实值,但gsettings显示默认值
这是否意味着它gsettings不适用于我的系统?如果是这样,我该如何解决这个问题?
我想找到.html一个文件夹中的所有文件并将其附加[file](./file.html)到另一个名为index.md. 我尝试了以下命令:
ls | awk "/\.html$/" | xargs -0 -I @@ -L 1 sh -c 'echo "[${@@%.*}](./@@)" >> index.md'
Run Code Online (Sandbox Code Playgroud)
但是它不能@@在命令内部替换?我究竟做错了什么?
注意:文件名可以包含空格等有效字符
澄清:
index.md将每一行,[file](./file.html)其中文件是文件夹中的实际文件名
我已经pulseaudio-module-bluetooth使用apt.
$ type pulseaudio-module-bluetooth
bash: type: pulseaudio-module-bluetooth: not found
$ which pulseaudio-module-bluetooth
$ whereis pulseaudio-module-bluetooth
pulseaudio-module-bluetooth:
Run Code Online (Sandbox Code Playgroud)
显然,我正在寻找错误的东西。包不是简单地安装与包同名的命令。那好吧。
我想找出这个包安装的所有命令(或可执行文件)及其位置。
“如何获取有关 deb 包存档的信息? ”的答案告诉我如果我有.deb文件,如何查找包安装的文件。不过,我不是直接从.deb文件安装。我正在使用apt. 哪里是.deb该文件是使用?我的系统上是否有副本,我可以使用该问题答案中的命令进行查询?在哪里?
如果我的系统上没有本地副本,我可以获取一份apt吗?如何?
是否有一些方便的apt(或类似的)命令可以为我解决这个问题,这样我就不必dpkg-deb直接运行了?它是什么?
我可以完全在线找到软件包的文件列表,而无需明确下载任何.deb文件并且在安装任何文件之前使用apt? 如何?
目标:删除每个注释块除了最后一个注释行之外的所有注释。如果文件以注释块结尾,请将其完全删除。每个注释行都以#.
我试过的命令
sed -z -e 's/#.*\n#/#/g' "${InputP}"
Run Code Online (Sandbox Code Playgroud)
输入文件
# Life/Living
# Life/Passion
- [Mindfulness.md](file:///home/nikhil/Documents/Git/Life/Passion/PassionSrc/Sports/Yoga/Mindfulness/Mindfulness.md)
# Life/PersonalManagement
# Life/Social
# Linux/AmazingNotes
# Linux/Backintime
# Linux/DotFiles
# Linux/GitScripts
- [Peaceful.m3u](file:///home/nikhil/Documents/Git/../Mobile/Documents/PortableNotes/PortableNotesSrc/SocialActivity/Music/SongsPlaylist/Data/Peaceful.m3u)
- [AuxiliaryFiles.sh](file:///home/nikhil/Documents/Git/Linux/GitScripts/GitScriptsSrc/GitInit/GitNew/Src/AuxiliaryFiles.sh)
# PythonWs/NumericalProgramming
# PythonWs/Python
# PythonWs/ScientificComputing
Run Code Online (Sandbox Code Playgroud)
预期产出
# Life/Passion
- [Mindfulness.md](file:///home/nikhil/Documents/Git/Life/Passion/PassionSrc/Sports/Yoga/Mindfulness/Mindfulness.md)
# Linux/GitScripts
- [Peaceful.m3u](file:///home/nikhil/Documents/Git/../Mobile/Documents/PortableNotes/PortableNotesSrc/SocialActivity/Music/SongsPlaylist/Data/Peaceful.m3u)
- [AuxiliaryFiles.sh](file:///home/nikhil/Documents/Git/Linux/GitScripts/GitScriptsSrc/GitInit/GitNew/Src/AuxiliaryFiles.sh)
Run Code Online (Sandbox Code Playgroud)
# PythonWs/ScientificComputing
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决问题?
awk ×2
bash ×2
find ×2
gnu ×2
make ×2
alias ×1
apt ×1
boot ×1
cron ×1
dconf ×1
directory ×1
echo ×1
email ×1
filenames ×1
function ×1
gnome ×1
gnu-make ×1
gsettings ×1
linux ×1
logs ×1
networking ×1
screen-lock ×1
scripting ×1
sed ×1
services ×1
shell ×1
shell-script ×1
systemd ×1
systemd-unit ×1
ubuntu ×1
variable ×1
xargs ×1