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

17
votes
1answer
181 views

Switch to parent shell without logging out

Let's say I start in my local account: avindra@host:~> then I switch to root: host:~ # Then I switch to oracle: [ oracle@host:~] Is there a way for me to drop back into the root shell (the ...
1
vote
2answers
28 views

do not show error if file doesn't exist on copy, without sending to dev null

I want to avoid my script posting an error if I try to cp a file that does not exist. However, I would like error messages to print out for any other error, such as insufficient permissions. This ...
1
vote
1answer
32 views

What is Best Practice for running PHP in background?

When running the following on the command line it will be suspended until I issue the fg command: /usr/bin/php -r 'phpinfo();' & This is the case regardless if the PHP code is contained in a ...
1
vote
1answer
29 views

why does grep '\;.' expand to grep '\''\;.'\''' when executed over ssh?

$cat test.sh ssh HOST -l root -o StrictHostKeyChecking=no -q "/bin/bash -l -c /bin/env | grep -w PATH | grep '\;.'" $bash -x test.sh + ssh HOST -l root -o StrictHostKeyChecking=no -q '/bin/bash -l -c ...
2
votes
1answer
28 views

HISTTIMEFORMAT syntax

There are many bash guides that include adding lines such as HISTTIMEFORMAT='%d/%m/%y %T ' or HISTTIMEFORMAT="%F %T " to ~/.bashrc or /etc/bash.bashrc. There's always a space before the final quote. ...
3
votes
3answers
51 views

Redirecting stdout to terminal and file without using a pipe?

I have code, that goes something like this: #!/bin/bash VAR=0 func() { VAR=$((VAR+1)) echo 'Logging information.' } func 2>&1 | tee 'log.txt' echo "Should be 1: ${VAR}" When ...
1
vote
1answer
27 views

Process id of a command ran by an user

Consider i am running just some basic command.. ls Now would the above command have a pid, when it was getting executed? If yes, then how can i determine that pid? when i try echo $! right ...
3
votes
2answers
65 views

Am I hitting a race condition in bash?

I have a script which compares the output of a command with the output of the same command as it was ran previously, it works most of the time, but every now and then it doesn't work as expected. ...
1
vote
2answers
60 views

How do I expect 'echo -e “? \c”'?

I'm an absolute newbie to the UNIX world and have been asked to write a script that interacts with another one - but I'm stuck. The script that I interact with echos the following and I need to send a ...
4
votes
3answers
339 views

How can I start a process with any name which does nothing?

I want to start a process that does nothing but is still running. Say I start a process called sadhadxk, and when I run pgrep -x "sadhadxk" I will get the PID number back, like any normal process ...
1
vote
2answers
32 views

script to add users to otrs

Im looking for a fast way to import customer users into otrs (ticket system) I have an export from Active Directory with: firstname lastname password email username There is a script in the otrs/bin ...
8
votes
2answers
116 views

How can I conditionally pass a subshell through 'time'?

I have a setup script for a Vagrant box where I used to measure single steps with time. Now I would like to conditionally enable or disable the time measurements. For example, previously a line would ...
3
votes
1answer
33 views

Problem with passing parameters containing spaces and wild card characters

I have a problem passing parameters if the parameters may contain wildcards and/or spaces, if those parameters are optional. Since this sounds pretty abstract, let's have a small example: The ...
3
votes
4answers
62 views

Inner loop conditions shall depend on outer loop run

How can I build an inner loop such that the loop condition depends on the outer loop run? My very situation does probably not matter for the code I am looking for, but here it is: I have a crawler ...
2
votes
2answers
66 views

What is the purpose of using shift in bash scripts?

I have came across this script: #! /bin/bash ...
4
votes
2answers
107 views

Find and create empty files with the same name in another location

I want create empty files with the same name, but in another location. Is it possible? find some files use only filenames touch an empty file in another place Something like this: find . -type f ...
3
votes
3answers
56 views

source /dev/stdin doesn't work as expected

Let's start with simple tests that work for me to check that source /dev/stdin can be used at all. # echo -ne 'echo a\necho b\n' | source /dev/stdin a b Now I would like to source an actual ...
-1
votes
0answers
32 views

string bash variable value is not copied to another variable.why? [on hold]

I have this code snippet BCR2000_CHAN=$( jack_lsp | grep BCR2000 | grep capture | grep "MIDI 1" | sed -e 's/^.*\[\(.*\)\].*$/\1/' ) BRC2000_CHAN2=$( echo $BCR2000_CHAN | awk '{print $1}' ) ...
0
votes
1answer
40 views

replacing some text in square brakets in bash

I have this string that I get from running jack_lsp. a2j:Arturia BeatStep [28] (capture): Arturia BeatStep MIDI 1 in a xml file, I save the connections state from a previous jack session. ...
8
votes
1answer
257 views

Echoing progress from a background process without hijacking prompt

Consider the simple script hello: #!/bin/bash echo 'hello world!' Now from bash if I try to run this in the background: $ hello & [1] 12345 $ hello world! █ <--- prompt is stuck here until ...
0
votes
1answer
19 views

How to create a file name for the pipeline to delete all files?

So I want to delete all files in my current directory using the following pipeline: ls | sed -rn 's/(.*)\.jpg$/mv -n & \1.jpeg/pi' | sh How to create a file, named so that running the above ...
0
votes
0answers
10 views

I'm calling the Google Analytics Realtime API and getting back a JSON object. I need a script to determine if a value has changed [migrated]

I'm calling the Google Analytics API with an HTML page containing Javascript calls. It returns a JSON object like this: { "rows": [ [ "Submit", "6" ] ] } I'm currently ...
0
votes
1answer
59 views

bash: What is the difference between these two script variants?

(Note: Both of these examples may require GNU or BSD find and may not work as-is with the POSIX "edition" of find). Both of the scriptlets below must be understood as excerpts from way more complex ...
1
vote
2answers
46 views

How can I continuously run a bash script checking if a value has changed?

I have a PHP script getAnalytics.php that when called, returns a specific integer value. I want to be able to call getAnalytics.php in a bash script that runs continuously checking the PHP script ...
1
vote
1answer
25 views

Keep service running after ssh session ends [duplicate]

i have an ubuntu-server box to which i connect via ssh. now when i start a service (in this case teamcity) i would like to keep it running after the ssh session ends. right now the service stops as ...
1
vote
1answer
24 views

Shutter Script(s)

When i play some games with wine , i must not change the window , because of that , the game crash or that window are fill of black. im using xfce4 desktop , when i press "PrintScreen" key from ...
2
votes
1answer
44 views

How to count occurrences of all the words in all the files of a directory using grep? But with count incremented only once per word per file

I have already asked a similar question but people misunderstood what i was asking. I was asking how to generate a list of every word with a word count incremented only once per word per file. For ...
1
vote
0answers
15 views

How keep the correct output line of command [duplicate]

I need to keep the correct output of avconv command: filetype=`avconv -i first.mp3 2>&1` echo $filetype the results is an incorrect output. like this: avconv version 11-6:11-2, Copyright ...
-3
votes
1answer
18 views

redirecting output of command to variable

Easyly: export a=$(avconv -i "first.mp3") or export a=`avconv -i first.mp3` output of avconv goes to stdout and does not to variable a
-1
votes
2answers
135 views

delete files having a certain pattern in their names

I want to delete all files that have two numbers and a dot in beginning of their names for example: 01. abc 02. xyz
-1
votes
2answers
30 views

understanding sed, awk and curl interaction extracting ssh URL information from github page

I needed to pull every public repo in a user's GitHub account. To do this I got the API output of https://api.github.com/users/SOMEUSER/repos This is what I came up with. To extract the ssh_url line ...
1
vote
3answers
33 views

TAR Files: Move Files From Subdirectories to Main Directory

I've been trying to use this code: find documents -maxdepth 1 -type f -print0 | xargs -0 tar cvf documents.tar.gz to create a backup of the directory documents. The directory has the structure: ...
1
vote
2answers
74 views

How to rename file in bash script one by one

I have loads of files which look like this: data1.csv data2.csv . . data(n).csv My use case is that when I will call my script it will change data1.csv to data.csv and remaining files as it is and ...
2
votes
4answers
162 views

Extracting the second word from a string variable

I have a string "rtcpOnNbActive true" stored in a variable x. I want to extract "true" as substring and store in a variable. How can I do this?
2
votes
1answer
60 views

How to make Bash loops

Is there a simpler way to make Bash loops? declare -a n=(1 2 8); for i in "${n[@]}"; do HandbrakeCLI (...) --title $i -o "$i.mp4"; done
1
vote
4answers
93 views

Killing a shell script running in background

I have written a shell script to monitor a directory using the inotifywait utility of inotifyt-tools. I want that script to run continuously in the background, but I also want to be able to stop it ...
1
vote
0answers
24 views

Expect works fine,but only in foreground why?

I use this script for update my repo slackware(generate asc,txt,etc) http://slackware.org.uk/people/alien/tools/gen_repos_files.sh I have "automated" it with my expect script #!/bin/sh set -e ...
4
votes
1answer
129 views

How do I use null bytes in Bash?

I've read that, since file-paths in Bash can contain any character except the null byte (zero-valued byte, $'\0'), that it's best to use the null byte as a separator. For example, if the output of ...
0
votes
1answer
45 views

How can I modify client SSH settings?

I am logged in a system as student. How can I modify client SSH settings so that when I write the following command ssh 123.4.5.67 , SSH client authentificates me as another user?
1
vote
3answers
53 views

How do you add a number as a command line argument?

I'm trying to add 1 number from the command line, and one number as like a default. For example: When user types in the number 50 the script will add 10 ( as the default number). ./script 50 The ...
1
vote
3answers
52 views

Calculate and round numbers up in bash

I'm struggling with a slight variation on: How to calculate by taking first field and How to round floating point numbers in shell? I have a file that looks like (space between columns): 1533 ...
11
votes
3answers
725 views

How do you continue a sentence with a command inside

For example, I have been trying to say "There are 10 people online at the moment" in my script file. I can never seem to get the command working without the "people online at the moment" part on the ...
1
vote
1answer
47 views

Terminal title shows sudo, but I want command that's sudo'ed

So I've become pretty adept at the tasks here from editing all the posts to answering questions, so I think it's about time I ask one: Technical Information Distribution: Gentoo Desktop Environment: ...
2
votes
1answer
44 views

Can the shellshock bug be expoloited to run a command as a privileged user?

I am curious to know if the following command could be executed on a system/server with the Shellshock bug: curl -H "User-Agent: () { :; }; sudo /bin/eject" http://example.com/ (This code is an ...
0
votes
1answer
40 views

Weird bash expansion of ~bin

Today I accidentally typed ls ~bin I wanted to type ~bak - that's my junk backup folder, but ~b<tab> deceived me. Instead I got this: $ ls ~bin core_perl fogcoord ...
3
votes
1answer
134 views

bash: non blocking read inside a loop

I have a following small bash script var=a while true : do echo $var sleep 0.5 read -n 1 -s var done It just prints the character entered by the user and waits for the next input. ...
0
votes
0answers
33 views

Bash ignore “update” command

I have this in my .bashrc export HISTTIMEFORMAT="%Y/%m/%d - %H:%M:%S - " export HISTIGNORE="&:[ ]*:reload:update" export HISTCONTROL=ignoreboth:erasedups shopt -s autocd shopt -s cmdhist shopt ...
0
votes
1answer
35 views

Split the large files into sub files. How to do this process? [duplicate]

I have a large file in my unix box with 2 Gb. The files contains the xml lines. I want to split the files into say 10 files say each file is now of 204 MB ( approx ) so that combining the 10 files ...
9
votes
2answers
513 views

How do I force a user to change a password at the first time login using ssh?

I'm trying to force a newly created user to change a password at the first time login using ssh. For security reasons I want to give him a secure password until he logs in for the first time. I did ...
2
votes
1answer
15 views

How to make PATH variable exports on MacOSX persistent?

I do export http_proxy=http://proxy:8080 export ALL_PROXY=$http_proxy on my Mac. Brew for instance relies on these settings. How can I make these settings stick between power cycles? Is this the ...