我想检查主机名,以确保它们符合Bash Shell中的标准命名约定。
假设主机名是ab-cde-01
wolf@linux:~$ h='ab-cde-01'
wolf@linux:~$ echo $h
ab-cde-01
wolf@linux:~$
我一开始就构建了if else循环,它运行得很好。
wolf@linux:~$ if [ $h = 'ab-cde-01' ]; then
> echo $h is a valid name
> else
> echo $h is an INVALID name
> fi
ab-cde-01
这些是我的样本文件
user@linux:~$ ls -l | cut -d ' ' -f 10-
01. old Name.txt
02. old Name.txt
03. old Name.txt
test.txt
user@linux:~$
这就是我想做的。
user@linux:~$ for output in *'old Name'*; do echo $output; done
01. old Name.txt
02. old Name.txt
03. old Name.txt
user@linux:~$
因为实际的代码多次使用old Name
我尝试在bash脚本中使用history命令,但它没有工作。
bash文件的代码:
#!/bin/bash
# Copy history to file history
#cd /media/saleel_almajd/Study/linux/my_scripts/
echo "start Copy history to /media/saleel_almajd/Study/linux/my_scripts/history.txt"
export HISTTIMEFORMAT='%F %T ' #to make history and date apear
我有一个简单的bash脚本
#!/bin/bash -x
for line in `tail /home/user/line`
do
echo $line
done
但是不知道为什么它会回响所有的单词,而不是下面的每一行都是输出。
++ tail /home/user/line
+ for line in '`tail /home/user/line`'
+ echo Linux
Linux
+ for line in '`tail /home/user/line`'
+ echo is
is
+ for line in '`tail
Bash if条件在比较特定字符串时不匹配
匹配字符串:
Red Hat Enterprise Linux Server release 7.2 (Maipo)
代码:
machineOSVersion="Red Hat Enterprise Linux Server release 7.2 (Maipo)"
modifiedOSVersion="CentOS Linux release 7 OR Red Hat Enterprise Linux Server release 7.2 (Maipo)"
if [[ ${machineOSVersion} =
THis是我的代码
for /l %%i in (1, 1, %N%) do (
echo !v%%i!
for /f "tokens=* delims=" %%l in ("!v%%i!") do (
echo %%l >> Linux.cpp )
)
在这里,我想将%%l中的数据复制到linux.cpp文件中,如果%%l包含abc.cpp,则此名称存储在linux.cpp中。在这里,我想将abc.cpp中的内容存储到linux.cpp。
请帮帮忙
好吧。我又一次把头撞到Linux墙上了。我在这里做错了什么:
#! /bin/bash
echo
echo "1. Windows (Microsoft)
echo 2. Linux (Red Hat)
echo 3. MacOS (Apple)
echo
echo -n Select your OS choice [1, 2 or 3]: "
READ OS
echo
if [ "$OS" -eq 1 ]; then
echo "You picked Windows (Microsoft)."
fi
if [ "$OS"