我想检查主机名,以确保它们符合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
我有一个简单的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
echo $var命令可以很容易地调用bash中变量的值,如下所示
user@linux:~$ a=1; b=2; c=a+b
user@linux:~$ echo $a $b $c
1 2 a+b
user@linux:~$
我想要实现的是用x中的实际值替换a,b,c
user@linux:~$ a=1; b=2; c=a+b
user@linux:~$ for i in a b c; do echo "$i = x"; done
a = x
b = x
c = x
user@linux:~$
通过使用类似的for循环,我希望能得到这样的输出
a = 1
b = 2
c
这些是我的样本文件
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
我在学巴什。在做一个练习时,我犯了一个错误
ifs脚本要求选择,然后显示3条消息中的一条。该错误发生在选择之后。
#!/bin/bash
#nested ifs. script give user option to choose an OS.
osch=0
echo "1.Mac"
echo "2.Linux"
echo -n "Select your OS choice [1 or 2]? "
read osch
if [ $osch -eq 1 ] ; then
echo "You pick up Mac"
else ###
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。
请帮帮忙
在我的日常工作中,我使用TortoiseGit,并且我正在尝试编写一个结帐后钩子。我更喜欢在windows环境中工作,所以钩子文件所做的唯一事情就是调用标准的windows.bat文件:
#!/bin/sh
echo "The Git post-checkout Linux Shell-file has now started to execute"
cmd.exe "/c post-checkout.bat"
echo "The Git post-checkout Linux Shell-file has now finished executing&
root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# array=()
root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# for i in 1 2 3 4
> do
> array+=($i)
> done
root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# echo $array
1
root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# for i
#!/bin/bash
#Declare array with 4 elements
ARRAY=( 'Debian Linux' 'Redhat Linux' Ubuntu Linux )
# get number of elements in the array
ELEMENTS=${#ARRAY[@]}
# echo each element in array
# for loop
for (( i=0;i<$ELEMENTS;i++)); do
echo ${ARRAY[${i}]}
done
在第5行(ELEMENTS=${#ARR
好吧。我又一次把头撞到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"
我希望将输出保存到文件中,同时,我也希望看到屏幕上的进度。
基本上,tee只为一行工作。有什么解决办法吗?
[user@linux ~]$ cat -n test.sh
1 echo line 1 | tee out.txt
2 echo line 2 | tee out.txt
3 echo line 3 | tee out.txt
4 ls -lh out*
[user@linux ~]$
[user@linux ~]$ ./test.sh
line 1
line 2
line 3
-rw-r--r-- 1 user user 7 M
我正在运行以下脚本,将安装在系统上的CIFS共享文件复制到另一个目标系统。CIFS共享的绝对路径包含很少的空间,因此该路径失败了,我尝试在另一条不包含空格的路径上运行它,它工作得很好。我宣布CIFS共享绝对路径的方式似乎存在一些问题:
#!/bin/bash
set -x
BASEPATH="/mnt/smbdisks/IT_linux/IT Linux Systems Dev & Support/Testing/Operation/Hello"
ADVICES="World Country State"
make_folder()
{
if [