sh

Function return values within BASH if statements

若如初见. 提交于 2021-01-08 09:00:54
问题 I have looked at various ways on here handle function return values within BASH if-then statements, but none seem to work. Here is what I've got function is_cloned() { if [ -d $DIR_NAME ] then return $SUCCESS fi return $FAILURE } It will work if I call it on its own and check the return value like: is_cloned retval=$? if [ $retval -eq $FAILURE ] then ... fi How can I use the function call within the if statement? Or is there no way at all to take advantage of the return values? 回答1: if

Function return values within BASH if statements

夙愿已清 提交于 2021-01-08 08:53:14
问题 I have looked at various ways on here handle function return values within BASH if-then statements, but none seem to work. Here is what I've got function is_cloned() { if [ -d $DIR_NAME ] then return $SUCCESS fi return $FAILURE } It will work if I call it on its own and check the return value like: is_cloned retval=$? if [ $retval -eq $FAILURE ] then ... fi How can I use the function call within the if statement? Or is there no way at all to take advantage of the return values? 回答1: if

Execute a command in bash script [closed]

筅森魡賤 提交于 2021-01-07 06:31:32
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 27 days ago . Improve this question I'm trying to execute a command inside a shell script (in my case using sh as my shell) when the command is passed as the first argument to the shell script. Example: sh command_execute.sh ls -l Let's say I enter the above on the command line, ideally I would like the script

jq 1.5 multiple bash variables as argument

别等时光非礼了梦想. 提交于 2020-12-15 01:50:29
问题 I'm working on a script for my openwrt, a watchdog for my pia connection. I'm trying to make this little jq filter but every time I try I get error I've more options and I "compose" the jq filter all_region_data=$(curl -s "https://serverlist.piaservers.net/vpninfo/servers/v4" | head -1) BestRegion="italy" jq_filter='.regions[]' if [ -z "$BestRegion" ]; then # BestRegion not forced if [ "$pia_pf" = "true" ]; then jq_filter="${jq_filter} | select(.port_forward==true)" fi if [ "$pia_no_geo" =

jq 1.5 multiple bash variables as argument

99封情书 提交于 2020-12-15 01:45:52
问题 I'm working on a script for my openwrt, a watchdog for my pia connection. I'm trying to make this little jq filter but every time I try I get error I've more options and I "compose" the jq filter all_region_data=$(curl -s "https://serverlist.piaservers.net/vpninfo/servers/v4" | head -1) BestRegion="italy" jq_filter='.regions[]' if [ -z "$BestRegion" ]; then # BestRegion not forced if [ "$pia_pf" = "true" ]; then jq_filter="${jq_filter} | select(.port_forward==true)" fi if [ "$pia_no_geo" =

jq 1.5 multiple bash variables as argument

寵の児 提交于 2020-12-15 01:45:41
问题 I'm working on a script for my openwrt, a watchdog for my pia connection. I'm trying to make this little jq filter but every time I try I get error I've more options and I "compose" the jq filter all_region_data=$(curl -s "https://serverlist.piaservers.net/vpninfo/servers/v4" | head -1) BestRegion="italy" jq_filter='.regions[]' if [ -z "$BestRegion" ]; then # BestRegion not forced if [ "$pia_pf" = "true" ]; then jq_filter="${jq_filter} | select(.port_forward==true)" fi if [ "$pia_no_geo" =

jq 1.5 multiple bash variables as argument

佐手、 提交于 2020-12-15 01:45:30
问题 I'm working on a script for my openwrt, a watchdog for my pia connection. I'm trying to make this little jq filter but every time I try I get error I've more options and I "compose" the jq filter all_region_data=$(curl -s "https://serverlist.piaservers.net/vpninfo/servers/v4" | head -1) BestRegion="italy" jq_filter='.regions[]' if [ -z "$BestRegion" ]; then # BestRegion not forced if [ "$pia_pf" = "true" ]; then jq_filter="${jq_filter} | select(.port_forward==true)" fi if [ "$pia_no_geo" =

How can I fix Edit cancelled, no changes made in shell

落花浮王杯 提交于 2020-12-08 06:28:05
问题 I run kubectl edit deployment to change the version of one of my pods (this commands opens a temp file in my text editor and then I usually edit and close this temp file) and even before I close this temp file in my text editor I can see the following note in my bash. Edit cancelled, no changes made. It was OK before I installed fish and I tried to switch to bash but it doesn't help either. How can I fix it? 回答1: Things like this are most likely caused by it opening an editor that forks off

Why does sh interpret these commands differently to zsh?

狂风中的少年 提交于 2020-12-07 16:42:04
问题 Context: I am trying to get the names of fonts installed on my Linux machine. The name is between two colons. When I run this script using zsh, it works. When I switch to sh it breaks. It probably deletes \n characters, because the output is all one line. cmd="$(fc-list)" names="$(echo $cmd | grep -oP "(?<=: ).*?(?=:)")" echo $names Which command causes the issues? Is it not POSIX compliant? 回答1: Why does sh interpret these commands differently to zsh? Because they are different shell the

Why does sh interpret these commands differently to zsh?

核能气质少年 提交于 2020-12-07 16:39:25
问题 Context: I am trying to get the names of fonts installed on my Linux machine. The name is between two colons. When I run this script using zsh, it works. When I switch to sh it breaks. It probably deletes \n characters, because the output is all one line. cmd="$(fc-list)" names="$(echo $cmd | grep -oP "(?<=: ).*?(?=:)")" echo $names Which command causes the issues? Is it not POSIX compliant? 回答1: Why does sh interpret these commands differently to zsh? Because they are different shell the