请参阅以下会议记录:
$ mkdir temp
$ cd temp/
$ touch file{1..5}
$ ls
file1 file2 file3 file4 file5
$ SRC=file; TGT=ram
$ for f in file* ; do mv $f ${f/$SRC/$TGT} ; done
$ ls
ram1 ram2 ram3 ram4 ram5
$ PAT=ram/file
$ for f in ram* ; do mv $f ${f/$PAT} ; done
mv: 'ram1' and 'ram1' are th
我有一个/tmp/bash.sh,它包含这样一个脚本:
killall name*
如果我转到/tmp文件夹,然后运行./bash.sh,它可以很好地工作,但是如果我转到/,那么运行/tmp/bash.sh或./tmp/bash.sh就不起作用了。相反,它抱怨说
name*: no process found
为什么?怎么解决这个问题?
我正在试着写一个脚本来备份我的“我的世界”服务器,昨天它工作得很好,但现在不行了。
代码:
#!/bin/bash
mc_backup() {
now=$(date "+%Y-%m-%d_%Hh%Mm")
backupFile="$backupPath/${server}_${now}.tar"
cd "$serverPath" || exit
dir=("$(ls)")
for target in "${unwanted[@]}"; do
for i in
所选内容应基于执行脚本时提交的参数。
#!/bin/bash
#This script echoes a text and creates a file
echo "welcome. Will create a file with content in this folder"
ls -l | grep .txt > files_in_folder
我经常混淆Bash3.x外壳球形:
? # Match any single character.
* # Match any string of characters (up until the asterisk).
[set] # Match any character in set (but not the entire set itself).
[!set] # Match any character not in set.
使用regex (特别是PCRE)。
我的问题是,为什么不把这些看作"Bash“(就像我们有"JavaScript rege
我下载了许多YouTube视频,并希望使用bash脚本处理它们。然而,所使用的文件名包含各种特殊和非ASCII字符。
如何在bash脚本中处理这个问题?
假设我想要创建一个指向文件夹中每个这样的文件的符号链接:
# Write filenames to filelist.txt in parent folder
ls ./* > ../filelist.txt
# Create sym links for all files in filelist.txt
counter=0
while read video_name;
do
counter=$((counter+1));
我有一堆带有相关字幕的视频文件。我正在尝试编写一个bash脚本,将字幕和视频合并到matroshka容器中。
根据原始容器的不同,输入视频文件命名为"videoName.mkv“、"videoName.webm”或“videoName.mp4”。输入字幕文件命名为"videoName.languageCode.vtt“。输出视频文件命名为"subsvideoName.mkv”。
下面是我想出的脚本:
#!/bin/bash
for video in *; do
if [[ $video =~ \.(mkv|webm|mp4)$ ]]; then
我只是不知道我是该用球状还是用重击来对付bash。我写的关于bash脚本的书特别让人困惑,因为它没有澄清这个主题,而且我的理解永远都不正确。让我举一个例子,说明如下:这个。(点)字符的意思是“任何单个字符”。因此,a.c匹配所有的abc,aac,aqc等。
很好,我认为他错了,因为这是regex,但我做的第一件事就是测试它:
$ touch abc aac aqc
$ ls
aac abc aqc
$ ls a.c
ls: cannot access 'a.c': No such file or directory
然后我去谷歌全球化,并遇到这个帖子称为“全球教程”,我想,
我有一个KSH (not Bash)脚本,我想先发制人地检查文件计数。如果没有文件,我想打印“空”,然后退出。否则继续。
问题是当我执行文件计数时,它是空的,然后它就中断了。
代码:
###################################################
# Test to see if files exist in Drop Folder
###################################################
CONTENTS=$(ls ${gp_path}ALLSTUFF*.zip)
if [[ ${#CONTENTS[@]}
我在bash脚本中遇到了以下代码。
# See if bsdtar can recognize the file
if bsdtar -tf "$file" -q '*' &>/dev/null; then
cmd="bsdtar"
else
continue
'-q‘选项是什么意思?我在bsdtar命令的帮助消息中找不到任何信息。
谢谢!