Tagged Questions

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)

34
votes
2answers
2k views

How do I open an incognito bash session?

Is it possible to open an incognito session in bash? For example, when we need to enter passwords in commands and don't want bash to add them to history.
0
votes
1answer
68 views

How to wait until script ends - csh?

I execute a script that splits a big file into little files. Immediately afterwards I ask if (-f *filename) then .... Sometimes the script doesn't finish so the if doesn't work. I tried sleep but ...
9
votes
4answers
267 views

Unexpected EOF and syntax error

I am currently writing my third ever shell script and I have run into a problem. This is my script so far: #!/bin/bash echo "choose one of the following options : \ 1) display all current users \ ...
1
vote
3answers
62 views

I want to divide a sum of numbers by a value

So here is my code for Unix shell scripting #! /bin/ksh echo "Enter your first number:" read first echo "Enter your second number:" read second echo "Enter your third number:" read ...
2
votes
3answers
153 views

Call sed to replace a string stored in a bash variable

I want to expand a variable in bash with sed or awk. This variable is an array. For example, the script must delete strings contained in array. I tried ARRAY1=( string1 string2 string3 ) sed -i ...
4
votes
3answers
170 views

Script to compare 2 input paramters and show shared letter(s)

I am writing a script that I want a user to enter two separate words, and the result to show which letter the two words share. For instance ./share Cat Rat - would return shared letters: "a" and "t". ...
2
votes
1answer
110 views

Writing to an interactive prompt

I’m using the ftp command line tool and want combine scripted input with user input. With only user input the prompt looks like this: ftp> But when I try to insert some input with a script, like ...
4
votes
1answer
67 views

Length of argument inside a function of an sh script

I have a FreeBSD 9.3 RELEASE server and I am trying to write a shell script using sh. I am trying to get the length of a variable that is passed to a function in a shell script, like so: #!/bin/sh ...
2
votes
1answer
93 views

auto complete in shell script

My folders are named by date: 20140930DoingShellStuff 20140931HopefullyShellIsDone ... What I want to do is write a shell script to auto cd into the folder which corresponds to the current date. I ...
-2
votes
1answer
150 views

Delete all mails from inbox using linux command prompt

How can I delete emails from an individual email account? e.g. how can I empty userxyz@mydomain.com? I know the following: /var/spool/mail/mydomain /var/mail/mydomain I have many inboxes some of ...
0
votes
1answer
28 views

Replace copyrights recursively [duplicate]

I have many files under the current directory. Each file contains copyrights headers like, # # Copyright 2013 Company, Inc. All rights reserved. This software # is property of Company, ...
3
votes
4answers
344 views

How to return a background task to be in the foreground?

Well, the title does not say much, but I would like to know how to stop a running process after appending it with &. For example, I would like to install software foo. Now, assume, foo has many ...
0
votes
1answer
62 views

Unix: What happens if I enter ls -d [2-q]*

Would it just ignore the bit after the -d option since you cant arrange characters lexically between 2 and q?
1
vote
1answer
38 views

Can I use modulecmd with fish shell?

At work we use the Environment Modules package (and hence modulecmd) extensively. man module includes the sentence “The sh, csh, tcsh, bash, ksh, and zsh shells are supported by modulecmd.” This is ...
6
votes
1answer
131 views

cd and ls behave differently when inside a softlink to a dir

When we cd into a dir via its softlink, i observe: ls .. will show the content of the parent dir of the linked dir, while cd .. will go under the parent dir of the softlink. Why are they different? ...
1
vote
1answer
46 views

Run Comand on all files (folders ad subfolders) [duplicate]

All, I have a lot of PDF files. Does there exist a way to apply to all PDFs in folder and sub-folders at one time? Example, I have: /pdf/test/pdfa.pdf /pdf/example/aa/test.pdf I'd like to apply ...
4
votes
1answer
91 views

Problem combining -or and -exec with find command

I'm finding that when I use find's -or operator in combination with -exec, I don't get the result I expect. When searching for .cpp and .h files, the command works as expected if I don't use -exec: ...
10
votes
1answer
240 views

Why does `postgres` require a shell?

In my Debian Wheezy systems, I noticed that the postgres user 'postgres', the "PostgreSQL administrator", uses /bin/bash as shell. However, I cannot figure out why this is needed. Changing this to ...
0
votes
1answer
39 views

I ran `zsh -v` and now I have no shell history [closed]

I just installed zsh today to try it out. I was trying to check my zsh version and I accidentally entered zsh -v which is the verbose option. Now I can't seem to use reverse search on history. How ...
-1
votes
1answer
47 views

Redirect a directory as input to a script and output to a file

I want to use a directory name as a parameter for a pre-made script. Then the output goes into a newly made file in the home directory. It involves pipe/redirection. How do I do that? read dir $dir ...
7
votes
2answers
219 views

Why is a variable visible in a subshell?

The Learning Bash Book mentions that a subshell will inherit only environment variables and file descriptors, etc., and that it will not inherit variables that are not exported: $ var=15 $ (echo ...
3
votes
2answers
143 views

leaking memory with shell script and tty [closed]

I'm running a shell script on a raspberry pi to communicate with a arduino. Every hour my ram gets used up by about 50 megabytes more. The script itself just connects to ttyACM0 (the arduino's usb ...
5
votes
4answers
253 views

Is there a difference between read, head -1, and sed 1q?

The following commands seem to be roughly equivalent: read varname varname=$(head -1) varname=$(sed 1q) One difference is that read is a shell builtin while head and sed aren't. Besides that, is ...
15
votes
4answers
1k views

Do we have more history for cd?

cd - can move to the last visited directory. Can we visit more history other than the last one?
2
votes
4answers
92 views

Bash - How do I loop through subdirectories and extract the files

I have a directory called 10K_TIF (main directory). Within this main directory are multiple sub-directories each containing tif images. I want to read each TIF image and extract its path using a bash ...
4
votes
2answers
164 views

How to capture ordered STDOUT/STDERR and add timestamp/prefixes?

I have explored almost all available similar questions, to no avail. Let me describe the problem in detail: I run some unattended scripts and these can produce standard output and standard error ...
3
votes
2answers
93 views

Interacting with a running interactive console program from a different process

I have a console program with an interactive shell, similar to say, the Python interactive shell. Is there an easy way to start this interactive program A and then use another program B to run A? I ...
1
vote
1answer
284 views

/bin/sh: error importing function definition for `some-function'

I encountered this error when updating bash for the CVE-2014-6271 security issue: # yum update bash Running transaction (shutdown inhibited) Updating : bash-4.2.47-4.fc20.x86_64 /bin/sh: error ...
1
vote
1answer
58 views

Is it possible to create a Linux environment without a traditional command shell?

i.e. Using something like IPython, re.pl, or somesuch as a login shell, instead of bash/ksh/etc. Using initscripts, etc. written in Python or some other scripting language, and making no use of ...
0
votes
1answer
39 views

How to move cron commands into a script?

Can someone give me an example that shows how to put Cron commands into a script? Using these commands as an example: find /home/network/public_1 -type f -ctime -1 -exec ls -ls {} \; find ...
3
votes
1answer
49 views

Make program in a pipe to think it has tty

Test environment: $ mkdir testdir $ cd testdir $ echo | tee "file name" Now, ls will print file?name (under Ubuntu GNU bash, at least), while ls | cat will print file and name in separate lines. ...
0
votes
2answers
32 views

Rsync'ing system, exclude doesn't seem to work

I'm trying to make a full filesystem backup of a server through rsync, following this guide. I'm using the following command: rsync -aAXH --progress --delete --stats --exclude={\ "/dev/*",\ ...
0
votes
4answers
81 views

How to get process id of a command

We are running some command in batch mode. We need to do some more tasks once the existing command is done, so we need to wait until this command is done. For example: bsub -q gui -I calibre -drc ...
1
vote
1answer
142 views

How does Git change the shell prompt in Aptana Studio's Cygwin Terminal?

I'm running Aptana studio 3.3.2. The command echo $SHELL outputs /bin/sh. However there is no value for the PS1 environment variable which I would like to inspect. I cannot there is no .bash_profile ...
1
vote
1answer
77 views

Interactive Shell Session from Java

I want to run a series of commands from Java. I came across few forums that explain how to execute multiple commands using getRuntime().exec(command) and defining command as String[]. But I want to ...
0
votes
1answer
107 views

Copying files with multiple extensions

I would like to copy files with multiple extensions to a single destination directory. For example, I can use the following command to copy all .txt files in the working directory to a directory ...
3
votes
2answers
567 views

Assign Subshell background process pid to variable

I am currently starting a background process within a subshell and was wondering how can I assign its pid number to a variable outside the subshell scope? I have tried many different ways but MYPID ...
1
vote
1answer
25 views

Icon stops loading after the application restarts

I have a application which uses "self-restart" mechanism. It kills itself and runs again. When I run it first time (with .desktop file) it loads its icon correctly. The problem is that when it ...
1
vote
3answers
115 views

How to get the pid of a process and invoke kill -9 on it in the shell script? [duplicate]

I have an application server which we start by running this below command and as soon as we run the below commnad, it will start my application server /opt/data/bin/test_start_stop.sh start And to ...
1
vote
1answer
45 views

du skip symbolic links

I cannot find an example of what I want to do and, from what I'm reading, the default behavior of du on my system is not the proper default behavior. If I ls my /data folder, I see (removing the ...
1
vote
2answers
116 views

Why are UNIX shells like this and how can I work around it?

One of the things I've noticed about BASH and other UNIX shells is that, by default and when used in typical ways, they spawn subshells for almost everything. e.g. foo=$(grep "someword" ...
0
votes
1answer
44 views

Changing my default directory in passwd changes my prompt

I don't understand what's happening in this scenario. I changed the home directory of a user by editing the /etc/passwd file instead of using usermod -d. It worked: the default directory wasn't ...
0
votes
3answers
59 views

Shell pattern matching vs. regular expressions occurence [duplicate]

I am relatively new to Unix, and I stumbled across one curiosity. Some shell constructs like case or find, employ pattern matching, but it is not quite regex. Other commands, like ed, sed, vi, and ...
2
votes
2answers
52 views

List of subdirectories that contains a particular file name

I am wondering if i can do this in a single shell command. I am in home directory and want to find a list of subdirectories that contains a particular file. The file name and the depth is always ...
0
votes
1answer
65 views

How do I switch from bash to zsh? [duplicate]

I can start zsh with zsh. How can I make it be the default for new terminal windows? Will it be ok to copy my .bashrc to .zshrc to get things like my customized PS1 prompt.
-2
votes
6answers
271 views

How to change to normal user in the command line when logged in as the root user?

I log into an system through root via ssh. How do I become the normal user or another user on the system?
1
vote
3answers
153 views

How to find md5sum of files on remote machines by doing ssh?

I am running my below shell script on machineC which gets the md5sum of my files in my PRIMARY directory in machineC itself. #!/bin/bash export PRIMARY=/data01/primary for entry in "$PRIMARY"/* do ...
0
votes
1answer
53 views

Permission denied while getting the md5sum of a file using shell script?

I am running my below shell script which gets the md5sum of a files in my PRIMARY directory #!/bin/bash export PRIMARY=/data01/primary for entry in "$PRIMARY"/* do local_md5sum=/usr/bin/md5sum ...
2
votes
1answer
53 views

Bash - how to make explicit operator precedence without creating a subshell

I'm sure this is posted somewhere, but I haven't been able to find it. In Bash, how does one specify operator precedence (aka command grouping) without creating a subshell? In most other languages ...
4
votes
2answers
42 views

More shell scripts than one in one text file?

I am learning shell scripting for my introductory UNIX course at my university, and I`m curious if is it possible to have more than one shell script in one text file. What I mean by that is, for ...