bash's questions - English 1answer

13.800 bash questions.

I just wrote the following bash script to check the ping access on list of Linux machines: for M in $list do ping -q -c 1 "$M" >/dev/null if [[ $? -eq 0 ]] then echo "($C) $...

I have a program that expects arguments in the following syntax: prog [-f filename | -g filename1 filename2] ... Each filename must be prefixed with the -f flag. For example, the following are valid ...

Shell script scan network range for specific SNMP OIDs: #!/bin/bash # snmpget command poll the network range for certain OIDs for (( i=254; $i; i=$i-1 )) do host=10.77.32.$i; snmpget -v ...

How can you check if a command can be executable or not in Linux. Example: xeyes

How can I quote a string with single quotes? Eg, I can do: $ printf "%q\n" 'two words' two\ words $ Is there a way to get a single- (or double-) quoted string as output, ie: $ MAGIC 'two words' '...

I am parsing a file using grep and the output on screen contains newline, as here: $ grep 'gene' sequence.gb gene 89..1483 /gene="non-structural protein" ...

#! /bin/bash number=$1 if [ $number -gt 9 -o $number -lt 100 ] then if [ $number -eq 10 ] then echo Ten exit elif [ $number -eq ...

I am looking to get tab-completion on my command line aliases, for example, say I defined the following alias : alias apt-inst='sudo aptitude install' Is there a way to get the completions provided ...

I have the following loop, but it doesn't stop and produces the wrong dates. #!/bin/bash i=0 thedate="2018-03-28" enddate="2018-04-02" while [ "$thedate" != "$enddate" ]; do thedate=$( date -d "$...

In bash script I'm developing I'm trying to execute command and capture in variable(s): stdout stderr status code how to achieve that? The command is tar, if it is of any significance. I tried the ...

As a Linux user, I've always just used bash because it was the default on every distro I used. People using other Unix systems such as BSD seem to use other shells far more frequently. In the ...

I want to move a series of file into different folder based on their ID, but I want to make sure that the folder I'm moving the file to exists and is unique The folders have a matching ID as the ...

I try to change the directory inside a bash-script function, but it does not have any effect. Possibly, because the function is run inside a separate process... Here is a simple script without a ...

I want to create a bash script that would connect to a server and run jupyter notebook on that server. How do I run jupyter notebook command while I am connected to the server using bash script? I ...

I want to take down data in /path/to/data/folder/month/date/hour/minute/file and symlink it to /path/to/recent/file and do this automatically every time a file is created. Assuming I will not know ...

i'm trying to sort files with a date in the filename into folders based on that date. The files used to have a space in the filename, like this. There are a few older files, so I need to sort those ...

I just solved a problem with my Makefile(s). Make trips over every <<< with the error message /bin/sh: 1: Syntax error: redirection unexpected And I would like to know why. (I am using Bash ...

I am not able to understand ls and cd behaviour in following case : Create directory a/b/c $ mkdir a/b/c -p $ ls -lhRai .: total 324K 24512531 drwxrwxr-x 3 mayank mayank 312K May 22 16:23 . 24380771 ...

Meaning of '^[0-9]+$'?

4 answers, 735 views bash
What does this expression pattern '^[0-9]+$' check for? #!/usr/bin/env bash if [[ $VAR =~ '^[0-9]+$' ]]; then execute code fi

Hi I'm really new to writing scripts and I searched a lot but all that I've found is scripts with full access. I don't have access to the /etc. I'm working in a host in the cloud but I have limited ...

I have this array: PARAMETERS_OF_COMPONENTS[1]="component1" PARAMETERS_OF_COMPONENTS[2]="component21 component22 component23" PARAMETERS_OF_COMPONENTS[3]="component3" PARAMETERS_OF_COMPONENTS[4]="...

I am using the CentOS 7. I wrote my first bash script like this. #!/bin/bash echo 'this is my first code' and I saved it as hello_world I made a directory in my root home directory. mkdir bin ...

I have this variable : toto=123456 why does touch "$toto.hihi.log" works and creates a file called 123456.hihi.log but touch "$totohihi.log" doesn’t do anything ?

I have a simple bash script that starts two servers: #!/bin/bash (cd ./frontend && gulp serve) & (cd ./backend && gulp serve --verbose) If the second command exits, it seems that ...

Bash manual says that Expansion is performed on the command line after it has been split into words.. However, in the next sentence it states that there are seven kinds of expansion performed and ...

We have an Ubuntu 18.04 user that connects via SSH and has a restricted shell. More precisely, their shell in /etc/passwd is /bin/bash, but a command= setting in authorized_keys restricts them to ...

From bash manual Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard A double-quoted ...

I've just come across !$ (without quotes). I've not met this before and did some tests: $ ls -l (...some output...) $ echo !$ -l $ echo "!$" -l man bash says this in the section on history expansion:...

I'm new to bash scripting and I need help understanding this command: [ $? == 1 ] && return 0 Please explain what this means.

I need to add two arrays. (1 1) + (1 1) = (2 2) I cannot get my code to work and I have very little experience in cs. pls help! I have tried multiple resources for multiple days. thanks

I want check format keys in bash script. In my json if any keys match this format key[0-9][0-9]_$ my script exit 1 else exit 2. I want use JQ tools. Bash: #!/bin/bash json=$(cat <<EOF {"key11"...

I just installed fzf on Arch Linux 4.13.11 using pacman -S fzf. From bash, I can call fzf which lets me select files (using Ctrl + n and Ctrl + p) in the current directory and its subdirectories. ...

Why do the following examples from Arrow's reply output $var instead of 3? I single quote or backslash $var as '$var' or \$var, hoping that first $var will be passed literally into the execution ...

I need to create a deploy script to combine the following directory structure: ├── LIB_COMMON │ ├── file1.php │ ├── file2.php │ ├── file3.php │ └── file4.php ├── LIB_CZ │ ├── file2.php │ ...

I have a script doSmth in /usr/bin. Is it possible to get and print the directory the script was called from? So if I call doSmth from /home/me the output will be /home/me.

In R, We have IN operator to check whether or not the element is present in the specific column. For example: If we have fruits and market dataframe with fruit_name and products as the column name ...

When does history expansion happen? From bash manual Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ...

Is it possible to access json array with bash attributes? JSON example: { "data": [ { "id": 1, "name": "John" }, { "id": 2, "name": "Doe" }, .....

I see following code in a script: OLD_IFS="$IFS" IFS='something-special' # code that needs the special IFS # ... IFS="$OLD_IFS" If the IFS is not set before the script fragment then the script sets ...

I'm not quite sure what the issue is. I'm on Kali Linux 2.0 right now, fresh install. The following worked on Ubuntu 14.04 but it's not working anymore (maybe I accidentally changed it?). It looks ...

On ubuntu 15.04, I am running java app through vnc sessions. I have 8 defined sessions that are started during system boot. My question is, how do I create a script that checks to see if the process ...

How do I fetch the current terminal name? I mean to the name that ps shows in the TTY column, e.g.: root@dor-desktop:/home/dor/Documents/LAMP_setup/webs_install/do/install# ps aux | egrep 'mysql|(^...

$ ls -l /tmp/test/my\ dir/ total 0 I was wondering why the following ways to run the above command fail or succeed? Thanks. $ abc='ls -l "/tmp/test/my dir"' $ $abc ls: cannot access '"/tmp/test/my':...

I am using a Yocto image based on the linux-mainline kernel. I have systemd on the embedded OS that I have created. Aim I have a UMTS dongle connected to the board which will use usb_modeswitch to ...

In bash echo {{a,b}.{c,d}} expands to {a.c} {a.d} {b.c} {b.d} Though nothing is mentioned for brace expansion in bash manual for the type of input I have made My question is why the output is ...

As described here, redirections use open() to write to a file. There's an inner (?) file descriptor created in the shell, and then used when needed. Is the inner descriptor created for the whole ...

I'm using bash shell on Ubuntu Linux. I have this in my script output_file=create_test_results_file "$TFILE1" Through echo statements, I have verified that the value of $TFILE1 is a file path, e.g. ...

Wildcarding one part of the file name, ls says it exists: $ ls *rammar* London_Grammar_-_Hey_Now_Official_Video-nMEHJPuggHQ.mp4 London_Grammar_-_Hey_Now_Radio_1_s_Big_Weekend_2014-on1QEcz1sTI....

I remove some files using trash-cli: $ pwd /tmp/test $ sudo trash mfile $ Then I look for where the deleted file is stored: $ sudo ls /.Trash/0/ -la total 16 drwx------ 4 root root 4096 May 19 16:...

I have a following script scheduled to run every 5 minute that checks for two services and if it found any service status down,it sends email. Its working ok. But the issue is I want it to send UP ...

Related tags

Hot questions

Language

Popular Tags