有没有办法检查执行命令时是否有错误?
例子 :
test1=`sed -i "/:@/c connection.url=jdbc:oracle:thin:@$ip:1521:$dataBase" $search`
valid $test1
function valid () {
if $test -eq 1; then
echo "OK"
else echo "ERROR"
fi
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这样做,但似乎不起作用。我不知道怎么做
我有一个外置硬盘 TOSHIBA 1TB USB 3,权限始终为只读。
fdisk -l(输出):
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf2198b37
Device Boot Start End Blocks Id System
/dev/sda1 * 2046 362369023 181183489 5 Extended
/dev/sda3 362371072 976771071 307200000 7 HPFS/NTFS/exFAT
/dev/sda5 2048 976895 487424 83 Linux
/dev/sda6 978944 362369023 …Run Code Online (Sandbox Code Playgroud) 如何在 shell 脚本中读取文件,然后将每一行分配给一个我可以稍后使用的变量,(我正在考虑从文件加载默认设置的方法)
我已经尝试过:
process (){
}
FILE=''
read -p "Please enter name of default file : " FILE
if [ ! -f $FILE ]; then
echo "$FILE : does not exists "
exit 1
elif [ ! -r $FILE ]; then
echo "$FILE : can not read "
fi
exec 0<"$FILE"
n=0
while read -r line
do
(assign each line to an variable)
done
Run Code Online (Sandbox Code Playgroud) 我想编写一个带有多个输入框的 GUI 的 shell 脚本文件,供用户输入。我已经试过了zenity。任何想法或建议将不胜感激。
我在使用sed命令时遇到问题。我正在尝试编写一个执行以下操作的 bash 脚本:
:@:@并将其替换为新行如下所示:
#! /bin/bash
echo "Please enter the ip address of you file"
read ipnumber
find=`grep ':@' application.properties` # find the line
input="connection.url=jdbc\racle\:thin\:@$ipnumber\:1521\:billz" # preparing new line
echo `sed "s/'${find}'/'${input}'/g" application.properties` # replace old with new line
Run Code Online (Sandbox Code Playgroud)
问题是:什么也没有发生。
我已经尝试使用"${find}" 而不是'${find}'