Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

0
votes
1answer
12 views

Automate textual input to a command from a bash script

My question is quite similar to another one here but not quite the same. I have a sequence of commands to create an ssl key/crt ect. And I want to be able to create an automated, default one. These ...
0
votes
2answers
21 views

(standard_in) illegal character when looping through a for loop

I'm trying to get statistics related to processes and general system information. If I do it without looping it runs fine, but if I put it within a loop it just gives me a chained error of illegal ...
3
votes
1answer
28 views

Why the kernel kills my process with disown when I logout?

I would like to understand the behavior of a process running with disown when a SIGHUP (or similar) from a shell logout occurs. The process simply does the following: sleep 15 seconds print ...
0
votes
1answer
21 views

set a BASH variable equal to the output from 'top' command? [duplicate]

I know how to set a BASH variable equal to the output from a command, but it doesn't work in case of 'top' command for me, see below cat aTOPFWK.sh OUTPUT = $(top -b -n 1 | egrep 'fwk3' | awk ...
0
votes
2answers
36 views

Find the number of all typed commands which include a string , using grep

I'm searching through my bash history log for all the typed (started) commands which included the string x. For some reason, the homework checker always says that the number I'm giving is bigger than ...
6
votes
1answer
59 views

Why does a while loop stop after being suspended?

Why is it that using bash and suspending a while loop, the loop stops after being resumed? Short example below. $ while true; do echo .; sleep 1; done . . ^Z [1]+ Stopped sleep 1 $ ...
2
votes
4answers
182 views

Interactively add arguments line-by-line in bash

Sometimes it happens that I have a list of files or strings in the clipboard and want to paste it as an argument list in a bash shell: Example file list (only an example): createsnapshot.sh ...
2
votes
3answers
36 views

__git_ps1 (current branch) in bash prompt is always out of date somehow

My PS1 in my ~/.bash_profile: export PS1="\\n\[\033[38;5;246m\]\u@\[\033[38;5;245m\]\h\[\033[38;5;15m\] \[\033[38;5;28m\]\w\[\033[38;5;15m\]\[\033[38;5;2m\]`__git_ps1`\[\033[38;5;15m\] ...
0
votes
1answer
20 views

Need to get wget output to log file

I need to run several commands in my batch.sh script (e.g. wget) When I use ./batch.sh | tee logs.log only my script output is written in logs.log but wget output is absent in logs. How I can ...
2
votes
0answers
38 views

Move versus Copy

I've created a bash script that creates a handful of users then creates a .ssh folder and copies in their authorized_keys file. I've made sure to set the owner group to the specific user with ...
0
votes
0answers
20 views

shell script how to pass multiple arguments with a common name [duplicate]

I want to run myscript.sh in this way: ./myscript.sh -g 10.10.26.129 -n 10.10.24.0/24 10.10.48.0/22 n contains multiple arguments, and the number of arguments of n is undetermined. My current code ...
-1
votes
1answer
22 views

Read words with spaces as one word

I'm attempting to read words with spaces as one words and multiple spaces as a second word. Is there an easy way to do this: UNLIMITED TABLESPACE TRUSH SELECT ANY DICTIONARY ...
0
votes
1answer
24 views

Shell script using function to display system information sending errors

I'm trying to write a script to keep track of my system information. I want to use "function" in the script and just call the functions out. I'm having trouble with the commands working in the ...
2
votes
1answer
23 views

How to not show path after cd command with CDPATH set?

Setting the CDPATH variable is very useful, but it results in some not very nice result: each time I use the cd command, the full path of directory I want to move is printed. For example, if I am in ...
0
votes
1answer
14 views

Script for backup each DB on server but omit system databases

I have read a lot of post around this topic but I didn't found the one to fit my needs. So, basically I want to make two backups: one at mid day (12 PM) and the other at midnight (12 AM) for each ...
1
vote
3answers
26 views

kill bash loop executed from command line [duplicate]

I run my command in a loop. I wrote the loop directly to a bash command line: $ while true; do mycommand; done mycommand is a command doing a lot of io and waiting for events so it does not consume ...
0
votes
0answers
33 views

Breaking out of while loop with a switch case inside

I am having an issue with exiting a bash script out of a while loop: while read -r dir event name; do case $event in OPEN) chown $VHOST:$VHOST $WEBPATH/$name; echo "The file \"$name\" ...
0
votes
2answers
20 views

Telnet BASH script - Some commands are running out of telnet session

I'm running a bash script in order to get some data from a client. That is the script: host=2.218.71.67 port=23 login=xxx passwd=xxx DATE=date cmd1=ps cmd2=dumpmdm cmd3=sh cmd4=`cat /proc/meminfo` ...
1
vote
4answers
189 views

Bash: remove numbers (strip numeric characters) from string variable

I want to strip all numeric characters from a String variable, eg from: VARIABLE=qwe123rty567 to: echo $VARIABLE > qwerty I've search many posts but they either use sed to output to file/file ...
1
vote
2answers
53 views

Curl url txt file, but grep each url seperately from single file

Ok, here's one for you guys that is puzzling me. So I have a text file with lots of url's in it. I'm using curl -K "$urls" > $output to spit the output to my output file. Now for the output of ...
0
votes
1answer
26 views

bash script for service montioring with email alert and prevent repeated alerts

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 ...
1
vote
2answers
43 views

Insert text in specific lines of a file? with special characters

i know this has been answered several times, but i can't figure out how to use it for my project. i have several php files and want to add a new string between line 11 and 12. this is the string i ...
2
votes
1answer
56 views

Shell valid function name characters

Using extended Unicode characters is (no-doubt) useful for many users. Simpler shells (ash (busybox), dash) and ksh do fail with: tést(){ echo 34; } tést But bash, mksh, lksh, and zsh seem to ...
0
votes
0answers
18 views

Make whiptail work in a for loop

This is my first question ever here... So please be gentle :) I have a bash script that checks ping for 163 sites(stores around the country), which is this: #!/bin/bash #storestest.sh #version 0.9.2 ...
1
vote
1answer
21 views

Crontab and Tmux not playing well together

So I want my server to run a script which starts several tmux sessions on boot. This is my crontab: @reboot . /home/steven/.profile; /home/steven/Scripts/Start.sh And this is the content of my ...
0
votes
1answer
33 views

How to read variables from a php file in bash

How do I export variables from a php file in bash? I'm writing a bash script to read database names from config.php files of each website and then import the database from the backup repository. I ...
1
vote
3answers
16 views

Unable to Concatenate 2 Variables

I need to concatenate 2 string variables in bash on my Centos 6 machine for f in *.tar.gz; do basename ${f%.tar.gz} echo $basename dbaddress='mysql/*.sql' path="${basename}${dbaddress}" echo $path ...
2
votes
1answer
47 views

What purpose does reassigning a variable to itself via echo serve?

I ran across some bash code during a review that reassigns a variable to itself using echo. The variable is an array. The code basically assigns the variable to itself with `echo $a`. a=(one two ...
0
votes
3answers
27 views

regex - find invalid character

Using regex='^[]0-9a-zA-Z,!^`@{}=().;/~_|[-]*$' in below script file I am checking if a given string has any invalid characters or not. str="$1" regex='^[]0-9a-zA-Z,!^`@{}=().;/~_|[-]+$' if [[ ...
1
vote
2answers
21 views

Displaying a Date Variable

I am very new to shell programming and have a question. What is the best way to display the date right after it says "Creation date and time: " echo "What is your name?" read name echo ...
0
votes
2answers
32 views

Shell script using function () not finding command

I'm learning shell scripting and I'm studying how to use function in the shell script. The script is suppose to run as a basic math calculator with two defined numbers by the user. It's suppose to ...
0
votes
1answer
43 views

Regex - script check for allowed characters

I need to check a string and make sure that it does not contain any character outside list of given characters. I wrote one script to test this: str="$1" ...
0
votes
0answers
24 views

Using 'export' and 'xargs' in order to export environment variables from an separate file [duplicate]

I have a dev.env file that contains a number of environment variables. dev.env: APPLICATION_URL=http://localhost:8080 APPLICATION_DOCKER_IP=$(docker-machine ip default) ...
0
votes
1answer
13 views

Bash: Tab completion with cdable_vars

I've been relying on this hack for jumping around in the file system for a couple of years before finding out today that I can do the same thing using native Bash by activating the option cdable_vars. ...
0
votes
3answers
38 views

Current directory abbreviation rule in shell prompt

Sometimes I see that the current working directory in shell prompt is abbreviated and sometimes not. For example /usr/bin will be displayed as bin$ or /folder1/folder2 displayed as folder2$, in ...
1
vote
1answer
29 views

Find a “moderately large” divisor of a given number?

After processing some data, I get out a file that has a certain number of data points in it --- one per line. I need to pass these data points on to another tool that will do more number crunching --- ...
5
votes
4answers
101 views

Substitute Column With Result of Command

I'm trying to find a way to quickly and efficiently replace a column value for every row in a file with the output of a command. I need to work on multiple files with about 500,000 rows each daily so ...
2
votes
3answers
59 views

Random number generation in Solaris?

What is the best way to generate random numbers in Solaris? I can not seem to find a good answer for this. Most results do not work in my environment. There is a variable or command RAND that seems ...
2
votes
1answer
25 views

awk not doing a new line

I'm trying to print out the users who are currently logged in (each logged in user of each terminal). This is what I currently have: NOWDATE=$(date +"%Y-%m-%d") NOWTIME=$(date +"%T") USERS=$(who | ...
0
votes
1answer
31 views

How to remove the return code from the terminal prompt in Sugar on a Stick?

I am using Sugar on a Stick (Fedora 23) 0.106 for i686 as a distro. Here's the link to the website of this distro: https://sugarlabs.org When I use the terminal I get a very weird behaviour. For ...
0
votes
0answers
17 views

Bash previous command refresh is messed up [duplicate]

I'm running on a mac with el Capitan. I'm at the command prompt, running bash. When I hit the up-arrow, sometimes it's as if it thinks that my prompt is much longer than it is? The first part of the ...
8
votes
3answers
302 views

Compare two URL lists and print newly added URLs to a new file

I am initially producing two files which contain lists of URLs—I will refer to them as old and new. I would like to compare the two files and if there are any URLs in the new file which are not in the ...
3
votes
3answers
192 views

Reading stdin into a bash array

I want to accomplish the equivalent of: list=() while read i; do list+=("$i") done <<<"$input" with IFS=$'\n' read -r -a list <<<"$input" What am I doing wrong? ...
0
votes
0answers
52 views

Difference between two almost same command

Please consider two following command: $ echo ls | xargs -I cmd echo cmd | source /dev/stdin $ echo ls | source /dev/stdin What's the difference between these commands? In my machine the result of ...
-2
votes
0answers
34 views

I have an unexpected EOF in this, does anyone know what i am doing wrong [on hold]

#!/bin/bash # get hours for mynext in `grep $1 $2 | cut -d'(' -f2 | cut -c1-2` do let h=h+mynext done # get minutes for mynext in `grep $1 $2 | cut -d'(' -f2 | cut -c4-c5` do # for testing purpose ...
3
votes
2answers
386 views

Disallow execution in home directory

Is there any way to disallow file execution from home director in Linux? My target is to protect my system from malicious scripts etc. Sure, I can remove execution bit with chmod for /home/user and ...
-1
votes
3answers
31 views

Make directories and symlinks from names in textfile

I have a list of words in a text file, one per line. I would like to make a symbolic link for each of for each word in the text file. For example, lets say real directory is /stuff/testing/original ...
0
votes
0answers
31 views

How to properly execute a script from desktop on Mint KDE 17.2 and Cinnamon 17.3

I created a simple shell script and copied it onto desktop on the following systems: On Linux Mint Cinnamon 17.3 Beta: It asks me every time whether I want to Run in terminal, which I would like to ...
1
vote
2answers
42 views

Bash compose array with the input of other arrays, respecting a specific loop order

I am trying to generate a new array, with the combination of other arrays, respecting a specific sequence. In pure Bash. Example: numbers=(0 1 2 3 4 5 6 7 8); colors=(red blue green); ...
3
votes
2answers
310 views

what is the command [ -s “$NVM_DIR/nvm.sh” ] && . “$NVM_DIR/nvm.sh” doing

I found the following command in the .profile file while installing node through nvm: [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" I want to know what is the the purpose of [] and ...