Tagged Questions

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

3
votes
3answers
34 views

Help with expr and variables

Why won't this statement work? total=`expr $mPercent / 100 "*" .482 + $fPercent / 100 "*" .518` mPercent is a number as a result of an awk statement, as well as fPercent. I also get "expr: ...
0
votes
1answer
29 views

How does Bash pipe large amounts of data?

Let's say you want to cat the contents of a really big file, but want to view it a few bits at a time. Let's say one were to do the following: $ cat /dev/sda1 | less As a programmer of languages ...
1
vote
3answers
26 views

Command that passes its input through to output AND performs command?

I'm trying to use the quote program to make a little shell script that'll keep updating the stock prices every second. quote has to access the Internet and therefore has a small delay when it runs. I ...
0
votes
1answer
41 views

How can a script ask me questions?

I am using this script to analyse data: #!/bin/bash in=/autofs/cluster/transcend/mega/scripts/ insub=/autofs/cluster/transcend/mega/dtn/20141015/123 out=/autofs/cluster/transcend/mega/scripts/1256 ...
1
vote
3answers
47 views

Find and delete duplicate txt files

I have a folder with around 300 text files, is there any command that reads every every file indivdually and deletes the duplicate files? I mean the content and not the file names.
2
votes
5answers
71 views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
1
vote
2answers
47 views

What can I do if bash stops echoing?

One of the applications I use at work sometimes screws with my bash and so I don't see my own input anymore. I.e. $ echo foo foo $ becomes $ foo $ I incorrectly tried to run stty -echo which ...
0
votes
1answer
29 views

Open a new bash with sudo powers without reentering the password [duplicate]

I find very useful to have more terminal tabs in different current working directories. But if I need sudo privileges I need to reenter the password for every shell. Is there not a way to extend the ...
1
vote
1answer
32 views

How to execute recurring Bash script at specific times?

How would I set a script to execute on every Tuesday and Thursday at 11:50am? I've been looking at the at command, but I can't conceive how to use it the way I need to from its man page.
2
votes
0answers
19 views

Simulate Initial Login of user without using sudo

I'm writing a script to interface 2 third-party programs. (Datadog and AWS) The data mining script uses sudo -u to run my script. The script that I need to retrieve data from will segfault if ...
2
votes
1answer
53 views

How do I choose a file names with consecutive numeric suffixes?

I like to preserve things, so I want to preserve .bash_history. I would like to copy it into a directory using a script. Like here #!/bin/bash #Something here? number=~/Desktop/Coding/Bash\ ...
2
votes
1answer
41 views

Add content one file to another

FILE1=$1 FILE2=$2 if [ ! -e "$FILE2" ] then touch $FILE2 fi while read line; do if grep -q "$line" $FILE2 then echo else echo $line >> $FILE2 fi done < $FILE1 I want ...
1
vote
1answer
25 views

How to enable yank-nth-arg using vi mode on Bash?

Hey guys I'm trying to figure out how can I take my nth arg, from my last command, without using the !:nth. In a normal bash (emacs mode) I can do that using the follow shortcuts: <ESC>nth_arg ...
3
votes
1answer
38 views

How to call a shell script from Javascript code?

I am not able to call a shell script program from javascript(for example if someone will click a button in webpage then a script will run and will throw some output)???
5
votes
2answers
378 views

How to treat strings with spaces as a whole in bash? [duplicate]

I'd like to build an error handler which will make an empty file marked with the error_occur time. The core idea is to use the result of date command as a parameter. I did: time_stamp=$(date) touch ...
0
votes
1answer
53 views

Grep -m 1 doesn't work

I'm using the following command to parse a form element from HTML using grep. The $RESP variable contains the output from a previous curl request ... echo $RESP | grep -m 1 -o -E 'name="id" ...
0
votes
1answer
27 views

Bash Brace Expansion & Variables [duplicate]

I have a find command: find Directory/{Alpha,Bravo,Charlie} arg1 arg2 I want to replace Alpha,Bravo,Charlie with $find_dir find Directory/{$find_dir} arg1 arg2 however the latter expands to ...
0
votes
0answers
32 views

How to login as root [on hold]

I am new in this forum and Linux. I have a problem in my Machine. After I login as root to system, and if I try to do any thing, I get an error message as permission denied. I already checked ...
1
vote
2answers
163 views

What do square brackets in bash case statement mean?

http://ss64.com/bash/case.html SHOWS case word in [ [(] pattern [| pattern]...) command-list ;;]... esac What are square brackets indicating? Other websites omit them (i.e. no [[(] etc.) ...
25
votes
1answer
1k views

Why can Shell builtins not be run with capital letters but other commands can?

Why is this? When I do this CD ~/Desktop It doesn't take me to the Desktop. But this: echo "foo bar" | GREP bar gives me: bar
1
vote
1answer
25 views

Fastest way to find whether a file exists in a number of tarballs? [on hold]

Is there a more efficient way to do this other than using tar tf and checking the output of every file against the file that I'm looking for? This is the way I do it right now, but it's very slow ...
2
votes
1answer
54 views

why completion does not work for all aliases?

In my .bash_aliases file I have couple of aliases, like -- shopt -s expand_aliases alias emx='emacs' alias em='emacs -nw' alias gv='gvim' alias v='vi' alias ev='evince' when I use them and press ...
2
votes
0answers
56 views

Write the same file multiple times to one file using dd

I am trying to create large dummy files on a drive using dd. I am currently doing this: #!/bin/bash writeFile(){ #$1 - destination directory/filename, $2 - source filepath $3 - blocksize, $4 - ...
3
votes
4answers
322 views

How do I remove every number that's surrounded by <>

I have tried this sed -i '' 's/[0-9]*<>/g' But it didn't work. Example file: <Number1> </Number8> output: <Number> </Number>
5
votes
2answers
326 views

How do i populate end tags using sed, awk or any other command?

I have a txt file that looks like this: <sss>ss< or <firstword>anotherword< I want it to look like this <sss>ss</sss> or ...
1
vote
1answer
48 views

How to grep the logs for a list of patterns and make a report out of it?

I have a C++ executable which scan some of my files and those files has some user id in it. After scanning is completed it generates below log file (abc.log) like this - INFO [0x7faff2b32a00] ...
2
votes
1answer
51 views

Echo out lines of script before running them

Is there a way to run scripts in bash that makes it so that it prints each line of the script before executing it? This would be really useful to me for debugging... $./myscript.sh echo "Hello" ...
0
votes
2answers
65 views

Running Tasks in Parallel using Bash

I am using this script to analyse data. #!/bin/bash inlist=/aut/cl/tera/mja/scripts in=/aut/cl/tera/mja/data/ran_ready/ out=/aut/cl/tera/mja/data/mas/aft/ for i in $(cat $inlist/list.txt); do echo ...
0
votes
3answers
49 views

Pipe/redirect a group of commands

I currently use the following setup to redirect the output of multiple commands: echo "Some normal commands" ( echo "Error: something happened" echo "Warning: this incident will be logged" ) >> ...
0
votes
1answer
25 views

Getting video card product name in terminal

My laptop is equipped with an Intel i5-3317U CPU that, according to this, comes with an Intel® HD Graphics 4000 video card. However, with lspci | grep VGA I get "Intel Corporation 3rd Gen Core ...
-5
votes
1answer
57 views

Extract multiple lines from text file [on hold]

Source : ! hostname RTR-1 ! boot-start-marker boot-end-marker ! logging buffered 64000 informational no logging console ! interface FastEthernet0/0 description LAN ip address 172.16.29.250 ...
1
vote
1answer
42 views

I am try to interactively add a user via “useradd”

I am basically trying to write a simple script to allow for interactive use of "useradd" with select options. The options I am trying to allow for specific use are to either be defined interactively ...
23
votes
2answers
2k views

How does `cat <> file` work?

cat < file prints the contents of file to stdout. cat > file reads stdin until Ctrl+D is detected and the input text is written to file. cat <> file, at least in my version of Bash, ...
0
votes
1answer
33 views

Spaces in directory name Bash [duplicate]

I'm new to bash and I'm working on script that traverses the tar.gz file archive and in each file changes a string specified to an another string. Args of script: name of archive, searched string, ...
6
votes
2answers
163 views

Piping bash string manipulation

I've read some other piping bash string manipulation questions but they seem to be specialized applications. Essentially, is there a way to do the below simpler? instead of $ string='hello world'; ...
1
vote
1answer
48 views

How to fix corrupted bash-completion in command substitution?

it seems my bash-completion got corrupted. Every time I try to use command substitution, for example when I type ls $(ls Deskto<Tab> ..result is.. ls $(ls Desktobash unexpected eof while ...
2
votes
3answers
105 views

Write to stderr

I'm using stderred to color all output streamed to stderr red. It's working fine. But when I write my own bash script and throw an error with echo 'error' 1>&2, it doesn't color the output in ...
0
votes
2answers
58 views

Split XML file into multiple files

I have an xml file that have different nodes, I want to split files like this: <unix> <mm> </unix> <osx> <nn> </osx> When I run the script I want it to make ...
5
votes
1answer
55 views

Why different behaviour of trapping EXIT vs INT

Running bash 4.3 on Kubuntu Trusty 64 bit. Please see the following two files: trapping-int.sh #! /bin/bash trap "echo Exiting" INT cat </dev/urandom >/dev/null echo Hello trapping-exit.sh ...
1
vote
4answers
47 views

Mute system error message in a script file and display mine

I have created a simple script to move all the files with .sh suffix in the current working directory to a designated directory If there was no such file, the script should output only an error ...
2
votes
3answers
103 views

Using grep/awk/sed to sort and combine 2 files

Ok I am running into a problem. I am taking a wifi log that has MAC addresses listed in it. I want to find out what MAC vendors/manufactors for the devices that are connected to my router. I have 2 ...
0
votes
0answers
40 views

Why is a here-string command substitution considered as a single line?

I'm experimenting with while read syntax and there is a thing I don't understand. The most basic scenario which reproduces the problem is the following: a bash script a.sh calls another script b.sh ...
4
votes
1answer
39 views

Why does BASH process substitution not work with some commands?

On occasion process substitution will not work as expected. Here is an example: Input: gcc <(echo 'int main(){return 0;}') Output: /dev/fd/63: file not recognized: Illegal seek collect2: ...
0
votes
0answers
16 views

Specify a file with special characters in its name [duplicate]

$ ls -ltr total 8708 -rwxrwx--- 1 root plugdev 8293 Oct 17 02:39 --layout $ rm *ayout rm: unrecognized option '--layout' $ rm "*ayout" rm: cannot remove `*ayout': No such file or directory ...
6
votes
1answer
213 views

Does bash return anything when it runs a command?

I was found the guide to test if there is a bug in Bash. Namely, when x='() { :;}; echo VULNERABLE' bash -c x does not return anything, it is vulnerable. But are there cases like in C that bash ...
0
votes
1answer
43 views

Back-up script via bash — issues with file paths?

I'm trying to run a back-up bash script in via Plesk scheduled tasks on a CentOS GoDaddy Managed Dedicated Server. I'm having a frustrating amount of trouble with this (made worse by the fact that it ...
4
votes
5answers
196 views

How do I use the “if” command for multiple conditions?

How do I do this? if [ -f town-*.swf ] then mkdir towns fi This checks if town-*.swf exists, but I also need it to look for city-*.swf among others, so I need something like this: if [ -f ...
6
votes
1answer
109 views

Exclude one pattern from glob match

I have several files with the same base filename. I'd like to remove all but one foo.org #keep foo.tex #delete foo.fls #delete foo.bib #delete etc If I didn't need to keep one, I know I could use ...
0
votes
0answers
22 views

Are there scenarios where a space is required after a redirection symbol? [duplicate]

I was recently reviewing some old cron tasks and noticed that I had entries ending with >/dev/null 2>&1 instead of > /dev/null 2>&1 (note the space). That got me to thinking - ...
3
votes
1answer
97 views

What is the purpose of those special characters in the sed command?

I found this bash command that creates a directory tree in your console window. I find it quite useful, but I don't really understand how all of the special characters work. Could someone help break ...