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
17 views

Strange output when echoing variable from a different user

$ sudo su - user1 -c 'echo $DOMAIN_HOME' /app/user1/DOMAINHOME This looks fine, right? However, let's dig a little deeper: $ sudo su - user1 -c 'echo $DOMAIN_HOME' | tee test.out $less test.out ...
0
votes
2answers
20 views

Spawn multiple processes with a single command

Is there a way to create say 10 instances of a process (for example yes) with a single command? $instantiate 10 yes
-4
votes
0answers
38 views

What am i doing wrong with my script?

#!/bin/bash echo echo These are the Users Processes top -b -n 3 | sed -n '6,12p' pid= top -b -n 3 | sed -n '7,12p' | cut -f1 for pid in 'ps -ef | grep $pid | awk '{print $2 }'' ; do kill $pid ; ...
0
votes
2answers
29 views

Getting error with sleep and argument in sh script

I'm doing something like this #!/bin/bash END=3 time_w = 1 for ((i=1;i<=END;i++)); do # do something sleep time_w done but I'm getting sleep: invalid time interval ‘time_w’
0
votes
2answers
24 views

How can I break out of a while loop, from within a nested case statement? [on hold]

In the script below - which prompts the user to confirm that they want to proceed with running a potentially bad script - when the user enters Y at the prompt - it will break out of the case block, ...
0
votes
2answers
33 views

Using braces expansion to specify a set of paths: how to specify general branching principles? [on hold]

So, recently I've become obsessed with making an "elegant" CDPATH that suits my needs. While previously I had no idea you could use anything other than literal strings to define the variable, I ...
1
vote
3answers
33 views

Difference between sh -x and ./ for script execution

So I have a simple shell script. What is the difference between the two commands in execution? Is there a preferred way? $sh -x foobar.sh OR $ ./foobar.sh I found the script executed slower when ...
0
votes
1answer
22 views

How to ignore spaces in file path for bash select statement [duplicate]

I have the following Bash Script: #!/bin/bash cd ~/Library/Developer/CoreSimulator/Devices/; files=$(find . -name iaGambro_gambro.sql) select file in $files; do if [ -n "$files" ]; then ...
1
vote
1answer
23 views

finding a maximum and minimum file size along with their path in a directory

I want to find out the maximum, minimum and average file size along with their path. My code is: #!/bin/bash DIR="$1" echo "maximum file size:" du $DIR -h echo "average file size:" du $DIR -sbh ...
0
votes
0answers
20 views

how to run script with a clean login shell

I am connected to remote machine Linux RH6 directly via ssh (key imported on server), when I execute a shell script with arguments for restarting the java service, I have a strange issue with ulimit: ...
0
votes
2answers
38 views

No of files and directories in a particular directory in shell script

I am working on Linux and it's new to me. I created a shell script countfiledirs. I want to know the number of files and directories in a particular directory. My code is: #!/bin/bash echo "total ...
5
votes
2answers
148 views

Bash displays international characters as escape sequences

When I press certain keys (e.g. German umlauts) in the bash command line, I get escape sequences. For example, ß gives me \303. These escape sequences are treated as single characters, so one ...
3
votes
0answers
15 views

Search history from multiple bash session only when Ctrl + R is used, not when arrow keys are used

I usually have multiple bash sessions open. I want the history from multiple session to appear when doing a search (with Ctrl + R). When arrow keys are used only the current bash session's history ...
0
votes
1answer
17 views

How can I match and substitute this multiline pattern in a bash script?

I have a file jail.local and it has sections like this [apache] enabled = true logpath = /var/log/apache/error.log [ssh] enabled = false port = ssh I want to match on the string [ssh] and ...
2
votes
2answers
69 views

How is IFS really rendered?

I've read bash manpage and other docs, but I find the explanation a bit confusing. I have the following simple script: #!/bin/bash IFS="" echo $2 var=A B C echo $var if I execute it, eg: ...
-1
votes
2answers
23 views

How to use pass filename without extension to gedit external tool for make?

I am wanting to build and run a program called dbgen using the external tools. I know that this variable holds the filename, ‍‍‍‍‍‍‍‍‍dbgen.c‍‍ : $GEDIT_CURRENT_DOCUMENT_NAME How do I remove the .c ...
0
votes
1answer
37 views

List all file extensions in an arborescence and count number of occurences of each [duplicate]

I am looking for a simple shell function (bash prefered) to list all file extensions in an arborescence and count the number of occurences of each. For example, list_extensions . would return ...
0
votes
1answer
36 views

How can I populate an array in Bash Shell script loop

cmdline> ls -la /.myScript.sh set index=0 set usrlist[index]="null" while read line do #Total lines read z=`echo $line| wc -l` lines=`expr ...
10
votes
3answers
38 views

Why is my Bash script returning a syntax error?

I am writing a script which loops into recent files in a folder and executes a command... #!/bin/bash cd /home/Downloads recent_files = ($(ls -t | head -20)) for file in "${recent_files[@]}" do ...
-6
votes
0answers
30 views

Why changing variable position fixes the error [on hold]

I spent half hour trying to figure out why totusr=`expr $index + $totusr` was giving me syntax error then I did this totusr=`expr $totusr + $index` GUESS what its working.but why ?
-1
votes
1answer
53 views

what is shell script? [on hold]

Is that some thing like a programming language? Which does provide this option(facility) by a program running on linux or basic program that comes with linux kernel?
0
votes
1answer
44 views

How can I use sed to print out unique users [on hold]

I wish to print out the unique users in the system using only sed, using: ls -la | sed '/^$USER$/p' .... It gives me all files, matching to the current user, and prints out the lines they are in. ...
0
votes
1answer
21 views

Filtering Log Output on Separate Lines

I did a recursive grep in a directory to find all files that would match as follows grep -ER "match_string1|match_string2" /path/to/dir/ What I get as output is: ...
2
votes
1answer
95 views

bash time with nohup

I want to know how much time it takes to run something in nohup. I know this works: $ time sleep 2 real 0m2.001s user 0m0.000s sys 0m0.001s But why it doesn't work with nohup? $ nohup ...
0
votes
1answer
34 views

doubts in file system hierarchy? [duplicate]

explain the difference between /bin and /usr/bin used in Linux?
0
votes
0answers
26 views

include Forking - Multi threading in bash script to run it in upstart?

I have lack of understanding. Do i need to include forking in my bash script: http://stackoverflow.com/a/26756839/4749164, so i can use expect daemon/fork - option in upstart? i would like to run my ...
4
votes
2answers
37 views

How to kill a bunch of jobs based on ps output?

Here is output from ps $ps aux | grep blob ubuntu 4286 0.0 0.1 34748 9592 ? S Jan14 0:00 /usr/bin/python /usr/local/bin/pynt start_blob_reader ubuntu 4287 0.0 0.1 34748 ...
0
votes
0answers
12 views

Using brew: curl version error, “Incompatible library version” for libcurl.4.dylib

I used to have a working version of homebrew but then something broke today related to curl and libcurl.4.dylib— possibly a version or file location issue. I'm on Mac OS X 10.9.5 (Mavericks). For ...
-1
votes
0answers
28 views

Custom Command not found after sourcing .bashrc [on hold]

I wanted to add a function that could create custom alias so I added the following to .bashrc function addalias { echo "alias $1='$2'" >> ~/.bashrc } I then ran source .bashrc I tested ...
0
votes
1answer
42 views

What's the best way to make a bash function in a script as a parameter when running via command line?

I'm fairly new to bash scripting, and wondered what's the simplest way to make bash script functions in a script as the parameter when run via command line? Example usage: ./myscript function1 ...
0
votes
1answer
38 views

Log output from more than one script

I have a problem concerning the logging of a process: I have 3 scripts, a.py, b.py and c.sh a.py calls b.py and b.py calls c.sh The goal is to continuously log std out/err (write to file and ...
5
votes
3answers
72 views

How to undo changes in the commands-history?

In UNIX systems you can press top and bottom arrows to navigate through the previous commands. This is extremely handy. Sometimes, I go up and find a command that I want to use again, but with some ...
2
votes
2answers
33 views

universal help/man command: help builtin partial matches

I found a nice little script which iterates through a couple of manuals for a specific command. As a last resort, it will Google it and open a browser window. Source here: ...
0
votes
2answers
61 views

How to use 3rd variable in BASH for loop?

Good day. I want to parse data of particular columns from several files(aprilPlate.txt, mayPlate.txt, junePlate.txt, julyPlate.txt, augustPlate.txt) using For loop. The data of input files ...
0
votes
2answers
37 views

How to grep from command line for theses multiple strings?

I need to run a command to grep one of these strings from command line as web host disabled account to run website from browser until virus files are removed and I managed to collect few strings that ...
6
votes
2answers
33 views

How to check from bash if package exists in debian

I would like to make a installation bash script, where I would like to install mysql server. On linux mint I had followed code: apt-get -y --force-yes install mysql-server-5.6 but I installed new ...
1
vote
1answer
29 views

How to write a regex to look for strings with fixed length with at least one occurrence of a character

I've been doing some reading on regular expressions and thought I had everything covered, until recently. I've had to filter out all strings of length 5 which end with the letter t and contain at ...
1
vote
1answer
34 views

Script executes differently if run from udev

I'm having an issue with a script that seems really weird; it appears to stop executing prematurely when run from udev, but not when I run it manually from the command line. I've tried troubleshooting ...
0
votes
1answer
24 views

How to execute several lines into a .txt

I am using SSH; In a folder I have the next files: -rwxrwxr-x 1 german german 48 Apr 29 10:45 prueba.txt -rwxrwxr-x 1 german german 23 Apr 29 10:43 script1.sh -rwxrwxr-x 1 german german 23 Apr ...
0
votes
1answer
37 views

Script for update

I need your help in a script used for update : OLD="int 10" NEW="int 20" i=0 DPATH="/home" for f in $DPATH do sed -i "s/$OLD/$NEW/g" $f let i++ echo "modified:" $f done what i need ...
3
votes
2answers
114 views

kill: SIGSTOP: invalid signal specification error in bash script

When I use kill on command line it works. kill -SIGSTOP 1234 But if I use in bash script file I get this error: kill: SIGSTOP: invalid signal specification sh file is #!/bin/sh kill -SIGSTOP ...
1
vote
2answers
32 views

Dynamically create array in bash with variables as array name

This has been asked several times, but none of the methods work. I would like to dynamically create arrays with array names taken from the variables. So lets start with just one array for now: ...
0
votes
1answer
16 views

How to search for just new data and upload to mysql table,

I'm having a blonde moment. Problem Statement: So I have some timestamped data in a file which constantly at arbitrary intervals gets updated, and I just want to filter out data for the previous full ...
1
vote
2answers
32 views

How can I properly use the 'sed' s command in this particular scenario

There's a very simple question that's been bugging me about the sed command. Reading the documentation about this command has left me confused (mostly because English isn't my primary language). So, ...
2
votes
1answer
39 views

Execute commands from history that match regex or grep

I was wondering if its possible to execute commands from history that match a certain regex? I know you can do something like fc 232 248 And it will go into your history and then do revisions ...
0
votes
1answer
46 views

AWK is throwing an error “unexpected newline or end of string”

My Bash script: declare -a lang=('english' 'spainsh') sms="Free msg: Due to upgrades on apps you’ll need a new version by yyyy/mm/dd to app running. Visit a store or go to" url="google.com/UA2392 ...
0
votes
2answers
51 views

How to extract unknown arguments within a shell script?

I have a shell script that accepts a variety of options, some with arguments, some without, some short, some long. It should handle some of these options itself and pass on the rest it does not know ...
1
vote
1answer
42 views

How can I prepending a character for every output of a command?

I'm running commands which I want to specifically group them by every command, as shown in the example below. Tried printing with echo -e '| $line' but it only affects commands that output the text ...
3
votes
1answer
148 views

prevent a command from sending both stdout & stderr to any terminal or file [duplicate]

I would like to prevent my program from sending stdout and stderr to any terminals, files or devices. For this, I have three command crossing my mind, but I cannot distinguish their differences. Could ...
0
votes
0answers
38 views

How do I write a script for testing username/password? [duplicate]

I have about 500+ hosts I need to test a username/password combo to make sure there aren't any false positives in the list. I just need to make sure I can login and log out, no need to run anything ...