The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

0
votes
1answer
15 views

Why cant I overwrite a file with processed value?

This question prompted a thought I was not sure I understood well. I know that it is not possible or correct to use pipelines like cat myfile | grep -v mypattern > myfile due to how file handles ...
-1
votes
0answers
26 views

Insert the environment path to script file to read [on hold]

I have a text file which has user input i.e LD_LIBRARY_PATH. I want to add the that library path environment text into the script file (/etc/init.d/scriptfilename). Will it be possible?
1
vote
1answer
23 views

Does gnome-terminal modify PATH when invoking shell

I guess gnome-terminal might have modified PATH environ variable when invoking shell. Specifically, $HOME/.local/bin:$HOME/bin will always be appended to PATH. I did the following experiment to ...
5
votes
2answers
28 views

What exactly happens if input and output file is the same?

Let's say that I execute following command: tr a-z A-Z < file > file There are two redirections: < file and > file. Both are processed before tr command and as far as I know, if there ...
0
votes
0answers
15 views

Problem in writing to a File after Power on/off? [on hold]

I am writing the content of my script to a .log file using > operator. I am doing it on a Raspberry Pi. After a Power on/off if I try to execute the script it doesn't write to the file. I then ...
0
votes
1answer
27 views

In UNIX, how do I send a file back to it's original location after outputting it somewhere else? [on hold]

If I send a file into a directory using an output, is there a way to bring that file back to it's original location using a shell script?
2
votes
1answer
18 views

possible for mpv to find subtitle files by itself, something in config files?

Subtitle files come in a variety of formats, from .srt to .sub to .ass and so on and so forth. Is there a way to tell mpv to search for subtitle files alongwith the media files and if it does to start ...
0
votes
0answers
12 views

Delay in writing hexdump data to a file

I have a script which does hexdump along with pipeline commands and finally I am redirecting it to a file. Now I am logging data from the serial port of my Raspberry Pi. The data is received with a ...
0
votes
1answer
51 views

What is the meaning of xargs show limits output

You can use xargs to discover limits about the commandline you're using: $ xargs --show-limits Your environment variables take up 1901 bytes POSIX upper limit on argument length (this system): ...
2
votes
2answers
44 views

Delete directories that contain a certain file

I want to find all directories that contain a certain file and then delete those directories. With find . -name thatcertainfile -execdir pwd \; I get a list of all the directories I want to delete, ...
7
votes
1answer
1k views

Why does `grep fil*` fail?

I found echo file|grep fil* fails, but echo abcd|grep abc* succeeds. I don't understand it, can someone explain? Thanks
-1
votes
4answers
45 views

How to filter the table names from .txt file [duplicate]

select * from emp; select * from dept; selection end; I want to obtain this output: select * from emp; select * from dept; I tried by using: awk '/select/{a=1} a; /;/{a=0}' ...
2
votes
4answers
92 views

How to delete a tilde (~) folder? [duplicate]

I need to delete a "~" folder in my home directory. I realize now that rm -R ~ is a bad choice. Can I safely use rm -R "~"?
1
vote
3answers
38 views

Elegant way of counting how many times patterns from a file occur in another file

Imagine that we have two for example files. The first file is filled with unique names of employees created by combining the first two characters of the first name and the last 2 characters of the ...
8
votes
4answers
530 views

Bash program not executed if redirection would fail

In bash, I notice that if a command using redirection would fail, any programs which run prior to that are not run. For example, this program opens the file "a" and writes 50 bytes to file "a". ...
0
votes
0answers
17 views

Script generating dummy file with same content of my script while running my script [on hold]

I have a script (bit huge, so I could not post here). When I run the script: sh /home/user1/myscript.sh It generates a file named 1 (or sometimes ?). If I open the file with: vi /home/user1/1 # or ...
2
votes
1answer
19 views

Unable to redirect stdout/stderr to log file [duplicate]

I have a script tmp.sh #!/bin/bash echo hello sleep 3 echo 3 I want to log the script running time (as well as script stdout) to a log file. user$ time ./tmp.sh >& log.tmp real ...
1
vote
2answers
43 views

cd to original location when recording session with “script” command

I have script log.txt in my bash profile; that creates a new sub process and records my entire session to log.txt. When I press cmd+t to open a new terminal usually this will open one in the same ...
0
votes
1answer
40 views

How to find the parent of a file by inode

I want to use ntfsundelete to maintain the directory structure of the recovered files. The output of ntfsundelete is like this: Inode Flags %age Date Size Filename 191321 FN.. ...
0
votes
1answer
59 views

grep with variable in a variable

I want to filter the svlog file by date and split the result by the space, so when i enter the date, it didn't work for me, please refer to the script that I wrote below, the problem was in this ...
0
votes
2answers
42 views

How to convert indentation style in a project directory

First of all I am not sure that this is the place to ask this question. I am a web developer working on a medium sized team. We follow the same coding style using Lint/Hint tools. It happens ...
-1
votes
0answers
40 views

backup script for apache [on hold]

I got Apache installed on my CentOS and I'm trying to do the following as a routine checkup every time I run the script, which I will set up with cron. How can I fix the bash script? Task: 1st ...
0
votes
1answer
26 views

Why does Grave operator changes output format of the command? [duplicate]

Hello i want to ask why when i write ls -l there is new line after every row but when i assign it to a variable myVariable=`ls -l` and than echo that variable echo $myVariable i get ...
-1
votes
1answer
34 views

for loop to evaluate multiple directories and execute command

I was editing a shell script and I want to know how can use for to use all directories listed by a list or variables and then execute a command. Example: I have this directories: /dirname1/app1 ...
0
votes
2answers
26 views

Having trouble deleting specific directories within a specific parent directory

I’m using Amazon Linux, bash shell. I’m trying to write a statement that will delete all child directories named “target” within a specific master directory. I would like to write things such that ...
1
vote
1answer
44 views

Creating a complex variable content by hand

I am creating a shell script dynamically and sending it to a remote server for execution. All is working except when I try to inject a variable with content coming from a file with multiple lines, ...
0
votes
0answers
27 views

What is the meaning of :- in unix? [duplicate]

Trying to understand the existing script where they have assigned ${3:-} to variable. Script : partition_parameter=${3:-} if [ -z $partition_parameter ]; then readonly drop_partition=false ...
0
votes
1answer
40 views

How do you put date and time in a file name?

I'm trying to execute a command and would like to put the date and time in the output file name. Here is a sample command I'd like to run. md5sum /etc/mtab > 2016_4_25_10_30_AM.log The date time ...
1
vote
1answer
33 views

Save cursor position and restore it in terminal

I am playing with some terminal capabilities to create async prompt output on bash. I want to get something like this: while outputting string in PROMPT_COMMAND, save terminal cursor position, print ...
-1
votes
1answer
25 views

Extracting several strings in a regexp

I have a FILE consisting of lines like the following: URL=http://someURL]somefilename I need to download the URL link if somefilename isn't already there. I wanted to use shell command like: for i ...
1
vote
4answers
44 views

Using cut to return the middle of a string

I have an xml string echoed to stdout along the lines of <xml:attribute>{41c33a-4893b-3627a-617a}</xml:attribute> I want to return the string {41c33a-4893b-3627a-617a} in this case. I ...
1
vote
1answer
37 views

Is there a standard abbreviation for 'find . -name foo' or do I need a function for this?

I recently used find . -name some-file-name a lot and decided that it's time to abbreviate this with a function (fb stands for find below): function fb() { find . -name "$1" } This seems to work ...
0
votes
2answers
22 views

Command Playlist like music.

So that idea has been in my head for a while, I often find myself launching a command and then wanting to launch another one after the one in progress finishes. The issue is that I have to monitor ...
0
votes
3answers
47 views

Comparing integers: arithmetic expression or conditional expression

In Bash, two integers can be compared using conditional expression arg1 OP arg2 OP is one of ‘-eq’, ‘-ne’, ‘-lt’, ‘-le’, ‘-gt’, or ‘-ge’. These arithmetic binary operators return true if ...
0
votes
2answers
48 views

What's the difference between using shell command (e.g. foo) directly and using $(foo)?

I get confused about using command directly and using $(foo). I'm using Mac, I try to list apps which is install by brew cask(a package manager), and echo each app. I have two short Shell scripts, ...
3
votes
1answer
145 views

Variables of integer type in Bash?

There are two ways to define and use variables of integer type in Bash declare -i a new variable use a variable in an arithmetic expression, without declaring it. My questions: What are the ...
2
votes
1answer
56 views

How can I check if a shell is login/interactive/batch in fish?

I want to be able to check if a fish shell is being run in login, interactive, or batch mode, and this question only discusses bash.
0
votes
1answer
33 views

Create HISTFILE in subshell

Here is my HISTFILE: $ echo $HISTFILE /home/Steven/.bash_history I can create it by using exit: $ [ -e $HISTFILE ]; echo $? 1 $ exit $ [ -e $HISTFILE ]; echo $? 0 However if I exit a subshell, ...
1
vote
2answers
17 views

Deleting lines by matching 3rd and 4th character only

I am running a script that fetches me the data as given below, 1400d2b8 1f4d1e2507 1200781e As you can see the 3rd and 4th character is 0 in line 1 and line 3. I am trying to write a single line ...
3
votes
3answers
34 views

How to pass array to bash shell script?

How do I pass an array as a variable from a first bash shell script to a second script. first.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') sh second.sh "$AR" # foo sh second.sh "${AR[@]}" # foo ...
3
votes
3answers
192 views

POSIX compliance of the cd program?

Is globbing and shell expansion same thing? I'm learning C by writing a custom shell and I'm also learning POSIX. Now I wonder if it is POSIX compliance that cd - takes you back and that ~ means home ...
-2
votes
1answer
39 views

Is a string an arithmetic expression?

In Bash, I use a string where an arithmetic expression is expected: $ (( hello )) $ echo $? 1 $ echo $(( hello )) 0 $ let aaa=hello $ echo $? 1 $ echo $aaa 0 There is no error reported. So is a ...
0
votes
0answers
13 views

TZ variable: strange behaviour using Etc/GMT+x? [duplicate]

Could anyone explain why the following commands return different results? TZ="Australia/Sydney" date TZ="Etc/GMT+10" date Sydney is 10 hours ahead of GMT, so the results should be equal, but I get ...
2
votes
1answer
24 views

Bash shell script program that prompts for and reads two integers from the user.

Okay, so I been trying to figure this problem for a while and I'm coming up with errors left and right. This is my first time trying to learn the basics. So any advice would be helpful! Problem: I'm ...
2
votes
2answers
53 views

Accessing array index variable from bash shell script loop?

I want to access the array index variable while looping thru an array in my bash shell script. myscript.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') for i in ${AR[*]}; do echo $i done The result ...
0
votes
2answers
73 views

Error when eval a for-loop

I am writing a script which accepts two arguments: #! /bin/bash eval for i in {$1..$2}; do echo $i; done I run it like: $ ./myscript 0002 0010 syntax error near unexpected token `do' Why is ...
-2
votes
1answer
39 views

What is the purpose of eval? [duplicate]

What is the purpose of running a command with eval? What kinds of commands can eval run? I find it can run builtin command, external executable command, pipeline, script. Can it run all kinds of ...
1
vote
2answers
50 views

Grep command using contents of a heredoc

I'm creating a script to update a remote computer and I want to know if any user is using the computer before I update. I have a list of users and I created a heredoc with all of them. The command I'm ...
-3
votes
0answers
43 views

How to write a script that checks for files in directories? [closed]

I am trying to write a shell script that checks files in few directories. ex:like AB/BC/CD/DE and AB/BC/CD/EF I need to check the files with previous date and need to read the file name,first line ...
7
votes
2answers
221 views

How to avoid space after bash variable in string?

I have a variable for color. I use it to set color to strings, by evaluating it inside the string. However, I need to include space after the name(so that the name doesn't contain part of the text). ...