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)

1
vote
2answers
30 views

expand wildcards “inside a command” instead of in the shell

(This is a simplest working example of something in a much messier context.) I have a directory d with files 1.txt 2.txt 3.txt 4.wav. My current directory is somewhere else. ls d reports 1.txt 2.txt ...
1
vote
2answers
39 views

How do I run multiple commands together in the background?

I know I can run a program in the background using &. command & However, I want to run multiple commands, and cd into a different directory while they are running. The multiple commands ...
-2
votes
0answers
26 views

Regarding shell script [on hold]

I have 3 servers, one is the app server and the other two are database servers. Following are the IP addresses of my servers: App server: 192.168.1.1 DB-server-1: 192.168.1.2 DB-server-2: ...
0
votes
3answers
30 views

Issue with the shell script after storing the directory in a variable

FTP is connecting to the server but i am getting an error - Enter if the env is dev or test or prod: test Please enter the id no : xxxxxxx Connected to xxxx 220 (vsFTPd 2.2.2) 331 Please specify the ...
4
votes
2answers
329 views

SH: How to make vars from one script available in the main script?

I have two scripts that need to run and both require the same variables set the same way. As a result I figured I'd break the setting of the variables out into a separate script. However, I can't seem ...
0
votes
0answers
37 views

Matching number using grep [on hold]

I have this text: yuiopao:##yuiopao:14975:Alex Vart student:/home/stud/yuiopao:/bin/bash polkovar:##polkovar:5004:John Adi student:/home/stud/polkovar:/bin/bash gfgfdgd:##gfgfdgd:11000:Alan ...
1
vote
1answer
51 views

Safe way to install .sh script in /usr/local/bin?

I want to include correctly the following script in Ubuntu 16.04. Code #!/bin/sh # http://tex.stackexchange.com/a/20886/13173 # $Id: pdf2eps,v 0.01 2005/10/28 00:55:46 Herbert Voss Exp $ # Convert ...
1
vote
1answer
41 views

Printing the file with number of hardlinks

I can print the number of hardlinks to files in directory by using find . type f -printf "%f %n\n" but this will also print the hardlink not only original files: Example: file1 is an original ...
1
vote
1answer
15 views

How do I interpolate a text file of 3D coordinates (X,Y,Z) onto a regular grid?

I have a 3D surface in a text file which I need to plot on a regular X/Y grid. However, the values for X and Y are not regularly spaced and are not necessarily in ascending order. I need to regularly ...
18
votes
1answer
1k views

Why is /etc/shadow shortening the password that I've set with the command: useradd -p?

[root@P-dude dude]# useradd -p $6$Ic2PVlwi$2nf.IRWTMy0FHrPza6mh5wjomwbYtIIxnzxPZL7yg8SsvOdbjEpoI0G8uy7AqduYKQOn2R/rnnaalRmfPMy.a0 bwong20 [root@P-dude dude]# cat /etc/shadow | grep bwong20 ...
1
vote
1answer
29 views

Shell is not listed in /etc/shells, when it is

I must be missing something simple here, because I am trying to make a user's default shell "lshell" for limited access. I try to set the shell with the command chsh -s /usr/bin/lshell userbut it ...
3
votes
1answer
57 views

How can I use the output of a command without using the mouse?

Imagine you issued a find command and now you want to use one line of the resulting output as an argument. $ find .. fileA fileB $ vi <CURSOR> # now do what to achive: $ vi fileB ...
0
votes
2answers
54 views

Using regular expression to extract content of file

I have a link and I would like to return only content between www. and .com e.g www.blablabla.com would return only blablabla How could I do that? When I use grep '\.[a-zA-Z0-9\.-]*\.' it gives me ...
1
vote
1answer
15 views

zsh fails at path completition when command is vim

When I try to autocomplete files (with vim as argument 0): vim ~/.conf <TAB> It shows: _arguments:450: _vim_files: function definition file not found _arguments:450: _vim_files: function ...
3
votes
2answers
52 views

Millisecond time in a shell script

How can someone print the entire time ie, for example 12:07:59:393(HH:MM:SS:milliseconds) in milliseconds. I found a lot of posts saying how to print Milliseconds along witht HHMMSS but I want to ...
4
votes
2answers
262 views

Float operations with bc not precise?

When I'm performing float operations in shell using bc, the result is not the same if I use a regular calculator. Am I doing something wrong? For example, I need to find a volume of a sphere. User ...
1
vote
1answer
105 views

Evaluation of find ( -exec )

I'm searching for all files that contain one of a set of strings. If they do, I change their access rights. find . -type f -exec grep -q '#!/bin/bash\|#!/usr/bin/grep\|#!/usr/bin/awk' {} \; -exec ...
3
votes
3answers
459 views

Is there a Unix equivalent of the Windows environment variable PATHEXT

I am wondering if there is a Unix equivalent for the Windows environment variable PATHEXT. For those with no Windows background: Adding a file suffix to PATHEXT allows me to execute a script without ...
-3
votes
0answers
33 views

How can we test POSIX compliance? [on hold]

If I want to test "POSIX compliance", can you help me script a test? I'm writing my own shell and I've scripted a test that succeeds, but my test cases are random and I don't know much about the ...
0
votes
1answer
19 views

Filtering time using last command on Solaris

I'm connected on server using Solaris and need to filter only people who were connected there until 28.4 00:00. How do I do that on Solaris? In bash I have -t option which does what I want.
0
votes
2answers
35 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
27 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
24 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
30 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
16 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
29 views

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

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
40 views

Play subtitles automatically with mpv

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
1answer
35 views

Script too slow ? Any particular reason?

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. I also call a python ...
0
votes
1answer
52 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
49 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
96 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
42 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
542 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
18 views

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

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
22 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
60 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
43 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
41 views

backup script for apache [closed]

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
41 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
36 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 ...