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

-1
votes
0answers
40 views

Prevent bash from opening links in browser [closed]

Whenever the response output from a shell command contains a url, bash will attempt to open it in a browser. Problem: Instead, I might want to just copy the url and open it in a different browser, or ...
3
votes
2answers
67 views

Execute code on remote machine and copy the results back

I'm using some old Fortran code that uses some peculiar memory handling. To make the long story short, it runs on my local machine but fails on the remote one. This is why I would like to ssh to my ...
2
votes
1answer
40 views

Help understanding the bash code? [closed]

What does this code do? export user=$(who am i | sed -e 's/ .*//') echo $user egrep -i "^www-data" /etc/group >/dev/null 2>/dev/null if [ $? -eq 0 ]; then group='www-data' else ...
2
votes
2answers
108 views

Left and right square brackets treated differently by sed/bash

I have a file with the following contents: [root@server list]# cat filenames.txt [AAA','ACMEDEMO2','ACMEDEMO3','ACMEDEMO4','RENTCOGH','TESTENT','DORASINE','LOKAWINK','BBB] [root@qa4app01 list]# I ...
4
votes
1answer
38 views

Are there problems with hyphens in functions, aliases, and executables?

In my testing (in Bash and Z Shell), I saw no problems with defining functions or aliases or executable shell scripts which have hyphens in the name, but I'm not confident that this will be okay in ...
4
votes
3answers
146 views

Change case of n-th letter in a string

I want to change the case of the n-th letter of a string in BASH (or any other *nix tools, e.g. sed, awk, tr, etc). I know that you can change the case a whole string using: ${str,,} # to lowercase ...
1
vote
1answer
25 views

Bash command to determine which string in a group of strings is a prefix of another string

Here's what I'm trying to do: I have a folder for code repositories, and I'm looking for a bash command that can tell the "code root directory" of the current working directory. For example, if I'm ...
3
votes
3answers
87 views

Why does my grep expression need to use $'string' to match tab characters?

If you take this code: echo -e '\t\t\tString' | grep '^[\t]*String' the result is blank because it doesn't match, yet this: echo -e '\t\t\tString' | grep $'^[\t]*String' works. I swear that I ...
11
votes
3answers
261 views

Get all possible combinations of a word in lower/uppercase letters

I want to write a bash script to print all possible lower and upper case permutations of a certain word, e.g. harley: harley harleY harlEy harLey ... HARLey HARLEy HARLEY My naive solution is to ...
1
vote
3answers
66 views

What return/exit values can I use in bash functions/scripts?

I want to know what return values we can use that will not be mistaken by for ex. SIGINT? ex.: $sleep 10 $#hit ctrl+c $echo $? 130 so I know I must not use anything like return 130 or exit 130 so ...
1
vote
3answers
38 views

How to remove matching files from directory A in directory B in the command line?

I have some duplicate files in directories A and B, how could I delete the dupes in B using the filenames from A in bash? How to do it in other shell's is a welcome bonus.
1
vote
0answers
32 views

How to force bash to start at index 0 with select output?

Well, even some less-experienced bash users would know meanwhile about the fact that bash arrays would always start with index 0. However, select will always do its own thing, as the following example ...
3
votes
4answers
115 views

Get pairs of lines and multiply [closed]

I'm trying to parse an html file for some values using bash. So I've got a big text file with numbers like this 3 2 4 2 What I want to do is get two lines, multiply both numbers and then store the ...
0
votes
0answers
57 views

Strange bash sytax error depending on sudo usage

I made this bash function to detect if the user running is actually logged in as root user and not using sudo by checking the uid + home directory of the user executing the command: #!/bin/bash set ...
0
votes
1answer
22 views

regexp in find to locate only

I have csv file (products.csv) with product numbers $ cat products.csv | head -3 2.20 2.21 2.22 in another directory I have thousands of product images in subdirectories. I need to locate product ...
1
vote
1answer
47 views

How do I define alias with variables which can be changed at runtime?

This is probably a very easy to answer question, but I could not find any questions already asking this due to different wording when writing titles. Running help alias on my bash prompt returns only ...
4
votes
2answers
84 views

Why does my Python background process end when SSH session is terminated?

I have a bash script that starts up a python3 script (let's call it startup.sh), with the key line nohup python3 -u <script> &. When I ssh in directly and call this script, the python ...
3
votes
2answers
140 views

Bash - echo line by line, ignoring the space between the lines

I had read the post on: bash - replace space with new line, but it does not helped to solve my issue. [My Directory] [root@testlabs Config]# ls Archive Backup_Files config_file.tgz ...
0
votes
2answers
45 views

Bash getting integer expression expected

I have following script to check disk usage #!/bin/bash # set alert level 90% is default ALERT=10 OIFS=$IFS IFS=',' storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " ...
1
vote
3answers
81 views

Add or subtract a number from the names of all the files in a directory

I have a number of png and jpg files whose names are numbers, e.g.0100.png, in a directory, How can I add 1 to their names, for example, to get 0002.png and 0003.png from 0001.png and 0002.png ...
-1
votes
1answer
39 views

how to patch bash vulnerability (shellshock) bug on RHEL? [duplicate]

We have over 10000 servers to patch for bash vulnerability (shellshock) bug. Now my question is what is the command to patch this bug ? And how we can check whether the patch has been installed and ...
2
votes
2answers
37 views

clipboard in bash

We can cut and paste current line in bash with ctl+u and ctl+y But I have read here that bash doesn't have clipboard concept, so how those shortkeys working? (or in another way: what they doing?)
0
votes
1answer
29 views

Script a list of users who have been logged in for more than 24 hours?

I am attempting to create a simple script that will produce a simple list of users who are logged into a system for longer than 24 hours. I've seen the w command is good for being able to view idle ...
1
vote
1answer
31 views

Script to see if user has logged off

I have created this program to see if a user is logged on and it checks every minute. if [ "$#" -ne 1 ] then echo "Usage: mon user" exit 1 fi user="$1" until who | grep "^$user " > ...
4
votes
1answer
187 views

Why ZSH ends a line with a highlighted percent symbol?

I've noticed this on occasion with a variety of applications. I've often thought it was because the output was cancelled early (ctrl+c, for example) or something similar, and zsh is filling in a new ...
1
vote
2answers
21 views

Comparing value in same column and directing output to new column

I have my input file as DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0940 29343414 11 110005 DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 2336 29843714 11 110006 DPortal=ECCN ...
3
votes
2answers
220 views

Shell script wrapper to prevent running command with no arguments?

There is program I use, say xyz, that has undesirable effects if I run the command bare with no arguments. So I'd like to prevent myself from accidentally running the xyz command with no arguments ...
-1
votes
3answers
47 views

OR operator in bash scripting [duplicate]

This code generates a error line 3: [: missing `]'. So please anyone tell me that why i am getting such error.I am new in bash scripting. #!/bin/bash read x if [ $x == "Y" ] || [ $x == "y"] then ...
2
votes
1answer
26 views

Error passing variable from bash to php

I have the following files: vars.txt C=1234567890 Ascript.php #!/usr/bin/php <?php var $C="$argv[1]"; echo "\n $C \n"; $con = mysql_connect('localhost','root','123') or die ("No connected"); ...
1
vote
2answers
33 views

Randomize arguments ( that hold color codes) from an array

I have the array (shown below) with arguments that hold color codes. The intended purpose of my script is to randomize those arguments when the user inputs "scriptname randoms Text" so that every time ...
4
votes
2answers
411 views

Basic commands in Unix not working i.e: -bash: ls: No such file or directory

I'm new to Unix and in the process of installing a program for my dissertation I must have played with the PATH for the basic Unix commands such as ls. Every time I type ls and the directory name I ...
2
votes
2answers
81 views

Typing text from a shell script [duplicate]

I'm new to shell scripting. I'd like to know if there's a command similar to "echo" for displaying text in a terminal, but instead of simply displaying it immediately, it actually types it, like if ...
0
votes
1answer
41 views

Diff: slightly different filenames, same file

I'm using diff -rq to compare directories on a Mac OS X 10.6 server. In folder1, we have 'filename'. In folder2, we have'filename.archive' because folder2 is created by a file sync app that also ...
0
votes
4answers
54 views

Make WGET available without path

I have ready bash script, which extensively uses wget command. Unfortunately wget is not available at standard path, but available at: /usr/custom/bin/wget I was able to make it usable w/o path in ...
2
votes
2answers
119 views

Is there a special variable containing a case statement match

If you write a Bash case statement, can you get the current match without explicitly assigning it to a variable ? Consider case $(some subshell command sequence) in one) stuff ;; *) stuff ...
0
votes
1answer
27 views

Check for subdirectory

A)I used the following code to get the modified date of a file. But this is also selecting the subdirectories and thus returning an error. How van I fix this. for file in $1/*; do echo `stat ...
6
votes
1answer
152 views

Function that calls another function with list of arguments doesn't work

In my .bash_aliases I have defined a function that I use from the command line like this: search -n .cs -n .cshtml -n .html SomeTextIWantToSearchFor /c/code/website/ /c/stuff/something/whatever/ ...
2
votes
2answers
39 views

How to select unique array values?

I have an array and I want to get the unique 2nd members bash doesn't really have 2-dimensional array so I've defined it this way, using :: as the separator of the two elements: ruby_versions=( ...
0
votes
2answers
37 views

Cannot merge files using cat [duplicate]

I tried to open a lot of files (10,000+) with cat and them merging them into one like this: cat * > ~/Desktop/lol.xml But it returned this error: -bash: /bin/cat: Argument list too long This ...
0
votes
1answer
27 views

elif command is throwing error [closed]

Hi is the below elif command correct? elif [[ "${FILECOMMAND}" = "" ] && [[ -f ${ZIPFILE} ]||[ -f ${ZIPFILE3} ]]] I am getting an error when I run it.
1
vote
0answers
28 views

Automating sshfs not working

I want to mount a remote directory and I want to automate this. So I write below script which not working properly. #!/usr/bin/expect -f spawn sshfs vedams@192.168.5.109:/home/user /mnt/remote expect ...
1
vote
2answers
49 views

How to delete a word next of last slash

I have the following path : $ vim /path/to/some/where If I press Ctrl + w, It removes entire text to first space. The result would be : $ vim How do I delete just the word next of last slash ...
0
votes
1answer
38 views

how to reboot multiple computer using bash loop from the txt file

can anyone knows how to reboot computer in just one line code of bash (by looping itself). The details will be get from the text file which are the IP Address of each computer. When the script gets ...
1
vote
1answer
57 views

How to round floating point numbers in shell?

How do I correctly round IEEE 754 floating point numbers on the command line? I want to specify the precision of the output number - the count of fractional digits. Rounding 6.66 to precision 1 ...
3
votes
2answers
227 views

random permutation of lines of text

If I have a file with following content: 0001 0002 0003 0004 0132 0137 0138 0141 How can I get a random permutation of them in bash?
2
votes
1answer
60 views

Never clear .bash_history (HISTFILE)

Is there any command that I could use that makes .bash_history never clear itself? After a certain amount of commands it just clear itself. I think this works but I'm not sure? ...
5
votes
3answers
82 views

Shell/Bash script: Properly drop privileges

Okay, first of all, I know this question has been asked a few times here, but the answers given did not entirely satisfy me. The situation is the following: I have written many scripts to automate ...
-1
votes
1answer
44 views

Please elaborate the following script(5,7 lines)

#!/bin/bash # Declare array declare -a ARRAY # Link filedescriptor 10 with stdin exec 10<&0 # stdin replaced with a file supplied as a first argument exec < $1 let count=0 ...
3
votes
1answer
45 views

Scan ~/Downloads on new file creation

I want all new files added to ~/Downloads (and sub-folders) to be scanned with clamscan. When using Firefox on other OSes/Machines I've noticed that downloaded files sometimes get automatically ...
1
vote
1answer
56 views

Is there anyway to get COMPREPLY to be output as a vertical list of words instead in a single line?

COMPREPLY by default returns a space separated list of words, but I'd like to have it return a single word per line. I've tried putting newlines at the ends of the words and have looked through the ...