scripting

-z option inside if condition in shell script

荒凉一梦 提交于 2021-01-16 12:39:37
问题 Can someone post me the significance of -z option while writing if condition using shell scripts. Let me paste the exact condition what I am looking at if [[ "x$do_clean_flag" = "x-clean" && -z "$show_me_flag" && "$verify" = true ]] 回答1: From "help test": -z STRING True if string is empty. 回答2: -z checks whether $show_me_flag is defined check out the manual of test(1) 回答3: -z (something) means if (something) is NULL then return true http://unixhelp.ed.ac.uk/CGI/man-cgi?test suggests that zero

PowerShell - Use Dynamically Created Variable Name Within a Variable Name

◇◆丶佛笑我妖孽 提交于 2021-01-07 06:57:05
问题 So I have a powershell script that I am trying to get up and running. Most of it works but what I am trying to do to make it as easy as possible to run periodically is to have it reference a list of numbers (IPs) in a text file, and then create a new variable for each line of the text file. This part does work using the following. $iplist = get-content c:\powershell\ips.txt | where-object { $_.Trim() -ne '' } $startnum = 0 foreach($line in $iplist){ $startnum++ new-variable -name "ip$startnum

If i wanted to extract the ttl and display it from the ping command how could i go about doing that?

China☆狼群 提交于 2021-01-05 10:15:14
问题 Scripting and want to ping devices on a network, tell me if it's reachable or not, and then get the ttl data from the ping and tell me the operating system. Ive tried using the awk command, but I am also new to scripting and may not be using it correctly. for host in $(seq 1 255); do ping -c 1 $sn.$host | grep "Unreachable" &>/dev/null if [ $? -eq 0 ]; then printf "%s\n" "$sn.$host is Offline" fi ping -c 1 $sn.$host | grep "ttl" &>/dev/null if [ $? -eq 0 ]; then printf "%s\n" "$sn.$host is

If i wanted to extract the ttl and display it from the ping command how could i go about doing that?

两盒软妹~` 提交于 2021-01-05 10:14:29
问题 Scripting and want to ping devices on a network, tell me if it's reachable or not, and then get the ttl data from the ping and tell me the operating system. Ive tried using the awk command, but I am also new to scripting and may not be using it correctly. for host in $(seq 1 255); do ping -c 1 $sn.$host | grep "Unreachable" &>/dev/null if [ $? -eq 0 ]; then printf "%s\n" "$sn.$host is Offline" fi ping -c 1 $sn.$host | grep "ttl" &>/dev/null if [ $? -eq 0 ]; then printf "%s\n" "$sn.$host is

If i wanted to extract the ttl and display it from the ping command how could i go about doing that?

流过昼夜 提交于 2021-01-05 10:14:15
问题 Scripting and want to ping devices on a network, tell me if it's reachable or not, and then get the ttl data from the ping and tell me the operating system. Ive tried using the awk command, but I am also new to scripting and may not be using it correctly. for host in $(seq 1 255); do ping -c 1 $sn.$host | grep "Unreachable" &>/dev/null if [ $? -eq 0 ]; then printf "%s\n" "$sn.$host is Offline" fi ping -c 1 $sn.$host | grep "ttl" &>/dev/null if [ $? -eq 0 ]; then printf "%s\n" "$sn.$host is

Proper way to use a trap to exit a shell-script in ZSH?

时间秒杀一切 提交于 2021-01-03 06:58:23
问题 I'm having trouble getting a trap function in a Zshell-script to work without exiting the shell. I have a simple countdown timer that I want to be able to interrupt using ^C, and when I do I want the trap to change the cursor status in the terminal. My syntax is: #!/bin/zsh trap 'tput cnorm; exit' INT TERM I've also tried: trap 'tput cnorm; kill -9 $$' INT TERM Both interrupts exit the shell entirely. How do I only exit the script and return to the command line? Any guidance will be most

Proper way to use a trap to exit a shell-script in ZSH?

梦想与她 提交于 2021-01-03 06:57:29
问题 I'm having trouble getting a trap function in a Zshell-script to work without exiting the shell. I have a simple countdown timer that I want to be able to interrupt using ^C, and when I do I want the trap to change the cursor status in the terminal. My syntax is: #!/bin/zsh trap 'tput cnorm; exit' INT TERM I've also tried: trap 'tput cnorm; kill -9 $$' INT TERM Both interrupts exit the shell entirely. How do I only exit the script and return to the command line? Any guidance will be most

Abaqus: script to select elements on a surface

被刻印的时光 ゝ 提交于 2021-01-01 10:07:35
问题 I am trying write an Abaqus/Python script that will select all the elements that "belong" to a certain face. I.e. taking all the elements that have a connection to one face of a meshed cube (I will calculate the total force acting on that face for force-displacement or stress-strain curves later). If I do it using the GUI I get: mdb.models['Model-1'].rootAssembly.Set(elements= mdb.models['Model-1'].rootAssembly.instances['Part-1-1'].elements.getSequenceFromMask( mask=('[#0:5 #fff80000 #ff #f

Abaqus: script to select elements on a surface

核能气质少年 提交于 2021-01-01 10:07:01
问题 I am trying write an Abaqus/Python script that will select all the elements that "belong" to a certain face. I.e. taking all the elements that have a connection to one face of a meshed cube (I will calculate the total force acting on that face for force-displacement or stress-strain curves later). If I do it using the GUI I get: mdb.models['Model-1'].rootAssembly.Set(elements= mdb.models['Model-1'].rootAssembly.instances['Part-1-1'].elements.getSequenceFromMask( mask=('[#0:5 #fff80000 #ff #f

How to get Command history by cursor key in Linux tclsh

不羁的心 提交于 2020-12-29 02:45:41
问题 Can get the command history by using cursor key (like up arrow key) in TCL shell (tclsh). I am running tclsh on fedora with linux version 2.6.21. 回答1: You want access to the readline library, you can do that with rlwrap: $ rlwrap tclsh Useful options are -c for file name completion, and -f to add words from a file to the completion list: $ rlwrap -cf my_complete_file tclsh Since you almost always want to use rlwrap , adding a shell alias is useful: alias tclsh='rlwrap tclsh' 回答2: I usually