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

2
votes
2answers
97 views

output both stderr and stdout on console and store them in a file at same time

may I output both stdout and stderr on console screen and store one of them into a log file? I write a test shell script: #!/bin/sh echo OUT! >&1 echo ERR! >&2 I can output both of ...
1
vote
1answer
63 views

How can I list hidden directories, then directories, then hidden files and finally files with ls?

I'm trying to figure out how to list the contents of a directory in the following group order: Hidden directories Non-hidden directories All other hidden files (including regular files, symlinks, ...
2
votes
1answer
69 views

Behaviour of 1>&0 in bash

So I am trying to learn more about file descriptors and their redirections. At the moment I am exploring an edge case of doing 1>&0 and I cannot quite understand what is happening there. $ ...
0
votes
1answer
32 views

Selectively record commands and output from terminal to MySQL table

In some situations I would like to store complete commands and output from terminal sessions in a MySQL database. Ideally I would just copy the command and output from the terminal to my clipboard ...
3
votes
3answers
204 views

Need to insert single quotes in text file for use as SQL query using sed

I have created a line of text that looks like this: INSERT INTO radcheck(id, username, attribute, op, value) VALUES (,,00:23:32:c2:a9:e8,Auth-Type,:=,Accept); I want to use sed to make it look like ...
0
votes
1answer
41 views

How do I write a bash script to report machine states and conditionally ping them? [closed]

#!/usr/bin/bash array1=( HPUX2 HPUX3 ) array2=( `cat $HOME/testo |awk '{print $2}'` ) The file testo,report HPUX2 OFF HPUX3 ON I want my script to report "Machine HPUX2 is OFF" and machine ...
1
vote
3answers
94 views

How do I test if an item is in a bash array?

Help for a simple script #!/bin/bash array1=( prova1 prova2 slack64 ) a="slack64" b="ab" if [ $a = $b ] then echo "$a = $b : a is equal to b" else echo "$a = $b: a is not equal to b" ...
0
votes
0answers
30 views

Pipe to `ls` Not Working as Expected [duplicate]

When I issue: [dave@dhost ~]$ which tar | ls -l I get the output of ls -l of the pwd. I expected to get: -rwxr-xr-x. 1 root root 395472 Feb 21 2013 /bin/tar Why doesn't the pipe work as I ...
2
votes
2answers
141 views

sudo as another user with their environment

$ whoami admin $ sudo -S -u otheruser whoami otheruser $ sudo -S -u otheruser /bin/bash -l -c 'echo $HOME' /home/admin Why isn't $HOME being set to /home/otheruser even though bash is invoked as ...
2
votes
0answers
42 views

Bash Executing Script from within Script Causes Echo and Read Issues [closed]

I appear to be having unexplainable issues with scripts run from within a subscript. I've been unable to acquire a solution so I will give you what I can to help me solve it. Problem: when a script ...
0
votes
1answer
38 views

For loop brackets - C like syntax

When i am using the below syntax to iterate why two brackets are needed ? for (( expr1; expr2; expr3 )) do command1 command2 .. done and the below code doesn't work ? and throws error "syntax ...
0
votes
1answer
38 views

bash shell - how to do nested loop without “syntax error: operand expected” [duplicate]

I am trying for i in {4..100} do is_prime=true a=$(($i-1)) for divider in {2..$a} do b=$(($i % $divider)) # <-- line 9 [ $b -eq 0 ] && echo 'y' #is_prime=false done [ ...
4
votes
3answers
142 views

Using | pipe character from a $variable makes it treat as just another argument in bash; how to escape it?

I have a bash script like this export pipedargument="| sort -n" ls $pipedargument But it gives the error ls: |: No such file or directory ls: sort: No such file or directory It seems to be ...
1
vote
0answers
29 views

Unable to create a configuration directory for [FishShell] Please set the $XDG_CONFIG_HOME variable

I'm getting this error when starting fishshell: melanie:~ melanie$ fish fish: Unable to create a configuration directory for fish. Your personal settings will not be saved. Please set the ...
0
votes
1answer
44 views

From Mysql query output to retrieve files in the file system and rename the files

I have to call a SQL query from bash that outputs 1000 rows of two columns File_Path (Eg., /opt/files/dest/2.bin) Name_of_the_file (Eg., fax attachment.pdf, invoice.docx... yes, there are spaces). ...
3
votes
2answers
78 views

closing parent process(terminal) doesn't close a specific child process

I'm new to Linux and so far,I have come to understand that if we open a new process through a gnome-terminal eg: gedit & "& for running it in background", then if we close the terminal, gedit ...
0
votes
0answers
13 views

Error opening terminal: Screen [migrated]

I just installed nano on my Nexus 9, which is rooted. However, when I try to run nano, it says "Error opening terminal: screen." bash-3.2# nano Error opening terminal: screen. Any help would be ...
7
votes
2answers
213 views

Shell script not able to awk created file

I'm trying to create some simple pass/fail test scripts, but I am having some challenges as outlined below. My intent is to get the full results of a command (such as ping) into a results.txt file to ...
0
votes
2answers
52 views

Combining two bash script and using a menu

I have two scripts, one that is used on a folder with csv files and another on a folder with .tar.gz files. In the second script, I first unzip the files before doing anything with them. Now I want to ...
3
votes
1answer
52 views

What is the difference between letting nohup append to 'nohup.out' and explicitly redirecting it to a file?

Consider the following scenario: tail.sh: #!/bin/bash tail -f test.txt invoke.sh: #!/bin/bash nohup ./tail.sh & invoke_explicitredirect.sh: #!/bin/bash nohup ./tail.sh > out.log & ...
1
vote
1answer
37 views

Echo newline with quotes [duplicate]

For: $hello="hello > world" Why does echo not print the newline for: echo -e $hello But if I put $hello in quotes it does. $ echo "$hello" hello world Is this because of ANSI-C Quoting? ...
2
votes
2answers
26 views

Current disk load

I'm using iostat to get the current disk load each second with iostat -dx 1 (specially, %util column). However, I'd like to put this in a bash script and control the interval with the watch command ...
2
votes
1answer
47 views

Concatenate and pass as parameter, bash

Need some help with removing default gateway. For example, there is an IP 192.168.4.15 with default gateway 192.168.4.14. I connect to WLAN with gw 10.0.0.1 and after that I would like do remove ...
2
votes
0answers
30 views

What are the benefits of using Tmux at all times? [closed]

I have been using the terminal for all of my local work, and have only been using tmux when I am ssh'd onto another machine and want to make sure I don't lose work if the connection closes. A software ...
0
votes
1answer
36 views

using CURL to transmit binary data over POST parameter

How can i use CURL to send binary data through a specific post parameter? E.g in: curl 'http://www.example.com' -H 'hi:hi' --data ...
-1
votes
1answer
29 views

Count values in first column where second column occurrences are the same in UNIX

I have to count values in first column of a file for which the second column occurrences are the same , using Unix. 12,abn 23,abn 45,hh 52,hh 89,mm 89,mm My output should be something like ...
2
votes
1answer
114 views

How to remove a filename from bash completion, based on its suffix?

Apologies if this is a duplicate, but I'm (unsuccessfully) trying to edit the bash completion options for vim. Specifically, when editing a LaTeX document, there are lots of supplementary files which ...
4
votes
2answers
87 views

Share environment variables between bash and fish

bash and fish scripts are not compatible, but I would like to have a file that defines some some environment variables to be initialized by both bash and fish. My proposed solution is defining a ...
1
vote
2answers
40 views

Checking URLs for HTTP code 200

I have a text file containing a list of URLs like this: http://somesite.com/some-article/ https://anothersite.fr/somepage.php?page=something What I'd like to do is check which URLs return HTTP code ...
1
vote
0answers
31 views

Career path with unix [closed]

I might get a -ve point hit for this one but i really need your opinion! I am a IT professional for about 4 years now (Support/application domain) with no as such expertise in one domain because i ...
2
votes
1answer
37 views

Input separator of the `read` builtin in Bash

Given such situation: echo "Please enter your name" read name # user enters: john smith echo $name # prints: john What could cause read to read only the first word of the input? Is there a ...
1
vote
3answers
34 views

the “done” message after a &-command is not displayed right away, but after a user action. Why?

I do a sleep 3 & and the "done" message is displayed as part of the ps command, not right on the console. It doesn't have to be ps. Any command after the sleep is done will have an extra line at ...
3
votes
1answer
32 views

Searching through C++ STL man pages without having to add “std::” every time

I have installed libstdc++6-4.7-doc on a machine with Ubuntu, so I could look up for things like std::pair from the command line. Is there a way to search for the same std:: entries without ...
0
votes
0answers
18 views

Makefile not prompting compiler to use optimization flag [migrated]

I have a simple makefile that I am using in bash to compile a C++ program and its associated .h files, not every .h file has a .cpp file associated with it. I wrote a makefile where each dependency ...
0
votes
1answer
31 views

Ugly bash function to send commands and “say” anything in screen over ssh. Is there a better way?

I’m working on a function this works but it is ugly. One thing that could be changed is being able to know the name of the screen. Using screen -dms minecraft java ….jar now starts a screen session ...
3
votes
2answers
79 views

Combining bash % with xargs %

This article says you can use a % syntax to remove file extensions: $ s=a/b.mkv $ echo ${s%.*} a/b How do you combine the % syntax with the % in xargs to achieve the desired result for a set of ...
2
votes
1answer
30 views

basename doesn't work as expected

How do I make ".mkv" disappear in the target filename? $ echo a/b.mkv | xargs -I % echo ffmpeg -i "%" $(basename "%" ".mkv").mp4 ffmpeg -i a/b.mkv a/b.mkv.mp4
2
votes
1answer
70 views

how handle a path ($1)

I've: /home/wms/mp3/ and /home/wms/tmp/ Inside ~/tmp my script: #!/bin/bash br=64 for a in "$1"*.mp3 ; do ffmpeg -i "$a" -ar 44100 -ab $br "$br""_tmp/${a%.*} ["$br"].mp3" ; done I do: ...
2
votes
1answer
87 views

Is there a difference between “gain root privileges” and “execute any command”?

I recently opened my sudoers file and noticed the following: # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ...
3
votes
2answers
59 views

Append unix timestamp to files with space using a script

This script works fine for all files recursively as well but it does not name files that has space in between. For example it throws error for the files "this is a test.txt" or "test file.txt" Any ...
3
votes
2answers
62 views

bash add path to handle some files

inside ~/mp3 I've some mp3 files. My script: #!/bin/bash br=80 for a in $1*.{wav,mp3} ; do ffmpeg -i "$a" -ar 44100 -ab $br "$br""_tmp/${a%.*} ["$br"].mp3" ; with $1 add the path: myscript.sh ...
1
vote
4answers
78 views

Executing a command within `if` statement and on success perform further steps

I was trying to execute a program which will create a directory on the basis of a complete path provided to it from the prompt and, if the directory already exists it will return an error (for ...
-2
votes
1answer
35 views

bash for loop to run ruby scripts

I'm trying to run several ruby scripts from the command line. Here is my code so far: for i in {1..59}; do $("ruby sample$i.rb"); sleep 10; done The purpose is to test all these scripts quickly, ...
1
vote
1answer
59 views

How to permanently enable scl CentOS 6.4?

I installed a newer version of devtoolset (1.1) and was wondering how I would go about permanently setting these to be default. Right now, when I ssh into my server running CentOS, I have to run this ...
3
votes
4answers
118 views

How to swap entire html blocks in multiple files with sed

I have tons of html pages with a simlar content as follows: <div class="wrapper"> <div class="aaa"> ...lot of html1 here like div's/spans etc.. </div> <!-- end aaa --> ...
0
votes
1answer
34 views

kill parent and child because endless loop

I have a process run by cron every hour. Such process calls another one (not sourced), ie: ./childProc.sh (Not sure if this detail is important) Because of an endless loop in child process (which ...
2
votes
1answer
73 views

Is replacing a particular line in a file through a bash script possible in VIM or EX?

I would like to modify a particular line, say line 5, in a file by using the EOEX construct how can I achieve my aim? The code snippet that I use to achieve my purpose is as follows: #!/bin/bash ...
1
vote
2answers
49 views

Replace user shell from dash to bash [duplicate]

Everytime I use my terminal, I am always put into the dash shell instead of bash. Is there any way to change this even just for my user only? Tried apt-alternatives but setting the default shell can't ...
5
votes
2answers
190 views

Bash limiting precision of floating point variables

In Ubuntu 14.04.1 LTS 64-bit bash I am declearing floating point variables by multiplying floating point bash variables in bc with scale set to 3; however, I cannot get the number of digits after the ...
0
votes
2answers
55 views

Bash Script Parsing Argument not working correctly

i have the following bash script (taken from FFmpeg) #!/bin/bash ################################################################################ # # Script name: MultiMedia Concat Script (mmcat) # ...