Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

learn more… | top users | synonyms

1
vote
1answer
10 views

Why does my while loop ignore the condition and keep going forever?

I have the following bash script which is supposed to record temperature data of my 2 cpu cores and send it to a file until the file is 10000 lines long, however the 10000 line while loop condition is ...
0
votes
0answers
23 views

Way to remove newline (^M) from variables only, not from file

I am loading a file into variables, the problem is that the file is formatted in Windows, I believe, so I get a ^M instead of a newline. How do I modify it when the value is in the variable? I am ...
0
votes
0answers
18 views

rename file with path name

I have some files of type .csv but they are named differently. Ideally, I would like the script to find all files with .csv type and rename file using its path name. Can someone help me restructure ...
1
vote
2answers
23 views

list subdirectory with some naming conversion

I want to write a script that will run a certain commands on my subdirectories with names containging or rather end with some strings, say, *-nom1, *-nom2, *-nom3. i.e. for dir in $(subs) do // do ...
0
votes
2answers
24 views

Use nested var for substitute var

I've a big question today ! I've made a little exemple of my situation. FOO="foo"; fooBAR="final"; var=${${FOO}BAR} echo $var I want to print "final". I tried all sort of things like ${${!FOO@}BAR} ...
0
votes
0answers
19 views

Shell memory location for typed in functions

If you type this in to the bash command prompt (not loaded into bashrc) function_name () { ls -1 ; ls -ltr ; } When function_name is typed in at the command prompt the shell will commit ls -1 and ...
1
vote
2answers
51 views

Bash script performance

In a bash script, some integers in a range are generated, concatenated with fixed strings, and printed on a file. OS is Ubuntu 14.04 and bash version is 4.3.11(1)-release. The strings (and so the ...
0
votes
2answers
20 views

Run previous command with multiple replacements

Many of you probably know that the commands ^foo^bar^ or !:gs/foo/bar are useful for running the previous command with replacing the pattern "foo" with the pattern "bar". But is there a way to ...
1
vote
1answer
23 views

use loop variable for calculation bash

for i in {0..9} do T=$(bc<<<"8+$i*0.5") echo $T done I get : syntax error near unexpected token `T=$(bc<<<"8+$i*0.5")' I believe the problem is the $i. What am I doing ...
4
votes
3answers
82 views

Unauthorized Installations in dnf after entering a command that's not found

I'm using Korora 23, which is based on Fedora 23. Whenever I type a command in bash that's not available, bash asks if I want to install a package to provide the command. Problem is, if I type y, it ...
-2
votes
0answers
22 views

check validity of input username [on hold]

I want to write a bash script that read an input and then check whether the input is equal to any users of ubuntu then login else again ask you to enter an input. function f{ echo"please enter a ...
0
votes
0answers
23 views

Forbid commands without leaving arguments [on hold]

I share my pc with nooby users. one of them is lil kid, and I use, for example alias chmod='echo "forbidden."' not to allow them to restrict files to each other. they are nooby, yes, but they may use ...
1
vote
2answers
42 views

Howto split stdin into multiple multiline strings and put each of them into different bash variables

I'm searching for a possibility to send via pipe several multiline strings to a bash script and grab each of them within this script. Finally, I want to store each multiline string into its own ...
0
votes
1answer
30 views

bash one-liner: set variable to output of command or to default value if output is empty

I know that in Bash you can use the syntax editor=${new_editor:-/usr/bin/vi} which will set editor to new_editor if the variable new_editor is not empty and to /usr/bin/vi otherwise. Is it possible ...
2
votes
1answer
27 views

How to tell the 'bottleneck' in a muti-pipe command

Say i have a command using several pipes. This could be any command but for example lets use this simple cut and sort. e.g cat data.tsv | cut -f1,5,8,12 | sort | uniq -c | sed -e "s/cat/dog/g" | sort ...
0
votes
1answer
28 views

Compare length of string AND if string contains numbers [on hold]

I'm trying to make a shell script where the user inputs a date and then the script is supposed to check to see if the date is in the valid format, mm/dd/yyyy; all numbers. I'm able to use substrings ...
-1
votes
0answers
30 views

for loop or while loop to read the fields of a file

I have two files File_1 and File_2 (reference file). I have to compare the 1st digit of File_1's 2nd column to File_2's 1st column for tagging and count. I also have to sum up the 3rd column of file_1 ...
3
votes
1answer
26 views

Executing the same command with different arguments in parallel [duplicate]

I think that xargs is intended exactly for this, but I tried using it and couldn't figure it out. I have a command foo -bar 123 --baz=whatever. I want a Bash one-liner to run three copies of it in ...
0
votes
2answers
34 views

Understanding what git branch means, in this context

I'm trying to understand what does this code means: function git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/' } but I don't get it. Someone said this ...
0
votes
2answers
63 views

Trying to complete Project Euler #5, passes all syntax checks but doesn't work

trying to complete Project Euler #5. The code I have should logically work, and it passes ShellCheck, but gives no output for some reason. The code is below. Thanks and sorry if this should be in a ...
1
vote
1answer
32 views

Pass Shell variable to awk [duplicate]

I realize this has been asked many times and many of the answers seam well written, but I'm missing something with my little task. Trying to pass a Shell variable (an argument in this case) to awk to ...
10
votes
4answers
860 views

How to get last part of http link in Bash?

I have an http link : http://www.test.com/abc/def/efg/file.jar and I want to save the last part file.jar to variable, so the output string is "file.jar". Condition: link can has different length ...
-4
votes
2answers
35 views

Script returning unwanted output

Here's what I currently have (top bash window) and the result the syntax returns (bottom bash window). When a name does not exist, such as "xyz" it returns the appropriate response. When a name does ...
1
vote
2answers
36 views

Turning off the monitor mode in Bash

Bash man lists under set subsection the option -m described so: Monitor mode. Job control is enabled. This option is on by default for interactive shells on systems that support it (see JOB ...
0
votes
0answers
27 views

Passing filenames with space between scripts [duplicate]

I've got a script that processes filenames given as parameters on the command line. This is a stripped down version to demonstrate the processing: #!/bin/bash # Just a test to see if parameter ...
0
votes
1answer
19 views

Checking if software is installed in SSH session

I am trying to check whether a certain package is installed on remote machine in bash script. If I execute the following statement on the machine itself the result is 1 (installed) in file check.txt, ...
0
votes
3answers
44 views

Rename a bunch of files, changing several substrings [duplicate]

I've got a bunch of files with names like image(1) image(2) image(3) . I'd like to rename those en masse along the lines of image1.jpg image2.jpg etc. I can do it in two steps by means of curly ...
-4
votes
1answer
37 views

Bash: integer expression expected

This recently stopped working. Any idea if I need to change anything in code? TIME=`grep real < /tmp/EV_Check.time | cut -d ' ' -f2` time=$TIME test $time -ge $ct result=$? if [ "$result" -...
0
votes
0answers
11 views

How to concatenate given line of bash history with specific operator?

I have a bash history like this: ... 504 cd path/to/directory 505 git pull 506 git add * 507 git commit -m 'update' 508 git push -u origin master 509 git add * 510 git commit -m 'update' 511 ...
3
votes
1answer
30 views

Increment counter in find -exec

I have a script that runs a number of processes like this ./myproc1 --out=1.xml ./myotherproc --out=2.xml ./mythirdproc --out=3.xml ./myfourthproc --out=4.xml # ... some more files I want to ...
10
votes
3answers
625 views

Bitwise shift and the largest integer in Bash

This is an exploration question, meaning I'm not completely sure what this question is about, but I think it's about the biggest integer in Bash. Anyhow, I'll define it ostensively. $ echo $((1<&...
1
vote
2answers
60 views

What happens if a users default shell is not installed?

I work as a sysadmin in a large company and have to maintain several windows and Linux (Ubuntu 16.04) VMs. Since I want to use zsh instead of bash on the Linux VMs, I have to change my default shell. ...
-2
votes
0answers
28 views

What problems or experiments did you try when first using the terminal? [on hold]

Relatively new to Ubuntu/Linux terminal and I'm wondering what most here did or experimented with when they became familiar with the syntax and implementation of code in the terminal. I know my way ...
0
votes
1answer
65 views

Batch rename files, create subfolders and move files by pattern

I have 500000 files in a folder and want to move them to subfolders. These subfolders should be created automatically. The pattern is {prefix}-{date}T{time}-{suffix}. The folder structure should ...
1
vote
2answers
68 views

Syntax error: “(” unexpected (expecting word) — in my bash script

I have a bash script: #!/bin/bash VAR1="var1" VAR2="var2" VAR3="var3" cat ${VAR1} \ <(echo -e '<something>') \ # <--------- here's the error ${VAR2}/...
-2
votes
0answers
34 views

How to pass a user input into a command line application via the command line arguments?

I have a command line application which requires a user input: ./some_application # something happens here..... # something happens here too..... Enter secret pass phrase: I want to call it from a ...
-1
votes
0answers
22 views

/etc/profile doesn't seem to be sourced in any situation

I added these to /etc/profile (Ubuntu 15.10). PATH=$PATH:/my/bin date > /tmp/etc_profile_date When I graphical login, /my/bin is not in PATH and /tmp/etc_profile_date has not been created. When ...
1
vote
1answer
26 views

Save temporary history via script

I want to save the temporary history to a file via script. In the bash it works like that: history -a /tmp/tmp_history But if I add this line to my script, the tmp_history is empty. I use it like ...
0
votes
2answers
34 views

Redirection using file descriptors - specific example [duplicate]

I am reading this linux documentation http://www.tldp.org/LDP/intro-linux/html/sect_05_02.html which gives the following examples about redirection and file descriptors. ls > dirlist 2>&1 ...
2
votes
2answers
32 views

Applying bash function to each file in subfolder recursively

I am trying to write a script that will apply a bash function for each file in a directory recursively. For example if the directory tests had all my files and sub-directories in it, the script find ...
2
votes
1answer
35 views

bash: cannot set terminal process group (-1): Inappropriate ioctl for device

Trying to execute the source command using "lfs" user on ubuntu 14.04 and getting this: root@linux:~/lfs# su lfs - -c "source ~/.bash_profile" bash: cannot set terminal process group (-1): ...
0
votes
1answer
33 views

Can I set add something to PATH, system-wide for all users, which has LOWEST precedence?

I can put this in /etc/environment and all users will have it: PATH=/opt/my/bin As I understand it, /etc/environment sets initial environment variables, then .profile, .bashrc and similar happen ...
-2
votes
2answers
41 views

Script to check if mounts are mounted or not

I am fairly new to script world. Learning from unix stack and blog. I came across this script here, #!/bin/bash A=``awk '{print $2}' /etc/fstab | grep -i "^/" | egrep -v '/etc/fstab|proc|sys|shm|...
0
votes
0answers
21 views

Load in environment variables when using sudo

If I perform the following command: sudo -i mongo -u $MDBUSER -p $MDBPASSWORD I can successfully connect using the mongodb shell. However: $ sudo 'mongo $MAUTH -u $MUSER -p $MPASS' sudo: mongo $...
0
votes
1answer
22 views

sh commands in .somefile

I am learning about the sh command and was the following instructions, and would like to understand what it does and its effects. //.devrun.sh CLUSTER_DISCOVERY_URL=mongodb://localhost/service-...
1
vote
0answers
60 views

Handling arguments in specified order in /usr/bin/printf or Bash printf

You know that the printf function written in C allows to do: printf('%2$s %2$s %1%s %1%s', 'World', 'Hello'); → Hello Hello World World But in GNU Bash: printf '%2$s %2$s %1%s %1%s' 'World' 'Hello'...
1
vote
0answers
37 views

Can bash expand a quoted and/or escaped string variable into words?

I have a bash shell variable containing a string formed of multiple words delimited by whitespace. The string can contain escapes, such as escaped whitespace within a word. Words containing whitespace ...
-1
votes
1answer
34 views

For loop with if else using unlimited variables

I am currently working with some of the functions in bash. But as of now I am very confused. Let me explain first what I want to do. Target Output: 2016-11-18T05:48:01 NFS="NFS1" MOUNT_STATUS=True ...
0
votes
0answers
26 views

SSH SendEnv and command=“script” overwrites EnvVariable

I've got the following problem: I try to push/set a EnvVariable via ssh -o SendEnv=APITOKEN host on the remote host is the following setup: this line in /etc/ssh/sshd_config: AcceptEnv LANG LC_* ...