在附加的脚本中,我尝试重命名一台PC,如果该PC有一个特定的主机名。但是,该脚本无论如何都会继续运行,并绕过if/else语句。
我做错了什么?我对Windows Powershell还不太熟悉。
谢谢!
# get current computername
$hostname = hostname.exe
#$env:computername
If ( $hostname = "CLNT3100" )
{
#Get all the computers with CLNT3* and sort them with the 'highest client' o
我正在写一个脚本,这可能是由bash或zsh的来源。根据shell的不同,我的脚本可能会执行不同的操作。目前我有:
if [[ -n $BASH_VERSION ]]
then
# Do the bash-specific stuff
elif [[ -n $ZSH_VERSION ]]
then
# Do the zsh-specific stuff
fi
问:有没有一种不同的/更好的方法来检测哪个shell提供了我的脚本?我知道$SHELL变量,但这是默认的shell,而不是生成我的脚本的shell。
作为linux脚本的新手,我曾尝试在test.sh中实现以下代码:
#!/bin/sh
# This is some secure program that uses security.
clear
VALID_PASSWORD="secret" #this is our password.
echo "Please enter the password:"
read PASSWORD
if [ "$PASSWORD" == "$VALID_PASSWORD" ]; then
echo "You have a
在busybox shell脚本test.sh (不是bash)中,如果我传入4个参数,如何直接从每个参数中获取值。例如
#!/bin/sh
args=("$@")
param3=${args[2]} #I want to get the value of the parameter 3, it works in bash
#but it does not work in busybox shell
如果我像这样运行脚本:
$test.sh 1 2 "3 4" 5
这样做的目的是希望在脚本中直接获得NO3字符串"
考虑以下shell脚本函数:
#!/bin/bash
declare -a dir
function() {
local -a directories=( "A/B/C D" "E/F G H" ) #Initialize local array.
printf "%q " "${directories[@]}" #"Return" values of array in escaped form.
}
dir=( $(funcion) )
for i in "${dir[@]
下面有一个脚本:
for (( i=0; i <= ( ${#arr1[@]} - 1); i++ )); do
if [[ ${arr1[i]} > 100 ]]; then
echo "=> x"
iptables -A INPUT -s 192.168.162.1 -j DROP
exit
else
echo "=> y"
fi
done
在我的数组中,no元素> 100,所有输出必须是"=> y“。当arr1[i]=1的时候,就没事了。输出:"=> y
我有一个shell脚本,我首先读取指定文件夹中的所有.s文件,然后用循环将它们编译为对象文件,然后将它们链接到可执行文件。这是:
FILES=PTscalar_1.0/mibenchforpt/security/sha/*.s
for sfile in $FILES
do
echo "------------------------------------------------"
echo $sfile
objectFile="${sfile%.s}.o"
exefile="${objectFile%.o}.ex"
我有一个任务,在这个任务中,我必须编写一个批处理脚本,在这个脚本中,我从用户那里获取输入,然后从那里调用一个shell脚本,传递用户输入值。知道我怎么能做到这一点吗。
下面是bat文件,我从用户那里获取输入,最后调用shell脚本test(test.sh),其中包含curl命令
@echo off
set /p technology="Enter technology: "
set /p job_name="Enter job name : "
set /p url="Enter url : "
test.sh
你能帮我解决这个难题吗?我正在尝试打印文件中字符串(即行#)的位置,首先打印到std输出,然后在一个变量中捕获该值,供以后使用。该字符串为“myFile”,文件名为“myFile”,定义如下:
this is first line
this is second line
this is my string on the third line
this is fourth line
the end
现在,当我在命令提示符下直接使用这个命令时:
% awk ‘s=index($0, “my string”) { print “line=” NR, “position= ” s}’ myFile
我
希望在perl中准备一个字符串,以便在bash中评估它,如下所示:
str="$( perl -E '$sq=chr(047);say qq{var1=${sq}hello world${sq}}' )" #this just for demo - the real perl scirpt is ofcourse real complex script ...
echo "got for eval: [[$str]]"
eval "$str"
echo "var1 : [[$var1]]"
它打印: