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)

2
votes
1answer
178 views

Screen - inherit current window's environment

In GNU Screen, how can I create a new window whose shell inherits the environment of the shell in the current window? The usual Ctrl+A C doesn't seem to do this.
1
vote
4answers
155 views

All subprocesses are Bash (!),

I was trying to use GDB, and found that whenever it attempted to spawn the program I was debugging, Bash was spawned instead (GDB would say starting myProg..., and then Bash would appear. When I ...
1
vote
1answer
141 views

Why does export not seems to affect child shells?

if I have $ x='This is a String' $ export x $ xterm & [3] 14089 The child process doesn't seem to respond to $echo $x $ Update: The FIRST time I export the variable it seems to span a ...
4
votes
2answers
538 views

“nohup sudo …” does not prompt for passwd and does nothing

When I run nohup sudo myscript.sh & I only get something like [1] 1220 in return and do not get prompted for a password. The process does not start either. I want to run this script in the ...
3
votes
2answers
58 views

Is there a way to condense ../.. parts of a path out programatically?

Say for example I have these types of paths to files in a script: /path/to/some/file/../../file1.txt Is there a command I can call such as readlink that will convert this path to its actual ...
2
votes
3answers
311 views

Forcibly create directory hard link(s)?

I understand the reasoning why nearly every unix version doesn't allow hard-linking of directories (in fact HFS+ on OS X is the only one I know, but even that isn't made easy to do yourself). However, ...
21
votes
3answers
10k views

Understanding IFS

The following few threads on this site and StackOverflow were helpful for understanding how IFS works: What is IFS in context of for looping? How to loop over the lines of a file Bash, read line by ...
9
votes
4answers
5k views

How to recover a shell after a disconnection

Am doing some work on a remote centos 5.6 machine and my network keeps dropping. Is there a way i can recover my hung sessions after i reconnect? EDIT: am doing some updating and installing with yum ...
4
votes
3answers
1k views

Summing up an array inside of awk?

I have the following piece of code: sum1= sum2= declare -a a echo $temp | awk '{split($0,a,","); name=a[1] ; for(i=2;i<=4;i++) sum1+=a[i] ; for(i=5;i<=7;i++) sum2+=a[i] }' This code is ...
0
votes
2answers
123 views

Monitor servers

I want to monitor three server pages. These three pages contain a simple text (for example it says it's "working fine"). I want to be notified when anything other than this message is displayed, e.g. ...
3
votes
2answers
119 views

Shell-independent way to cp dotfiles from a folder to another [duplicate]

I have two existing directories : foo: directory with dotfiles in it foo2: empty directory I would like to have a solution to copy all dotfiles in foo to foo2. I would like a solution that is not ...
3
votes
1answer
1k views

Wrapping a command that includes single and double quotes for another command

I recently learned about watch, but am having trouble making it work with relatively sophisticated commands. For example, I would like to ask watch to run the following command on zsh every three ...
2
votes
1answer
93 views

How to grep including single quote in a file

I have this line from file.php: 'user' => '', What would be the appropriate command using grep to query the exact line?
0
votes
3answers
138 views

Run two commands on same argument

I was wanting to maybe alias a command such that the command ran as per usual but also did something else on the argument/s before it was executed. An example might be: alias ls="echo displaying ...
6
votes
3answers
395 views

How to get mount point of filesystem containing given file

I am looking for a quick way to find the mount point of the file system containing a given FILE. Is there anything simpler or more direct than my solution below? df -h FILE |tail -1 | awk -F% ...
1
vote
2answers
54 views

What happens to argument in alias after using it once? [duplicate]

Why does this only print arg out once? $ alias test="echo $1 $1 $1" $ test arg arg This is on GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu).
6
votes
2answers
389 views

If I type “sudo” at the beginning of a one liner, does it apply to the rest of the commands?

If I type sudo at the beginning of a one liner in bash, does it apply to the rest of the commands? In other words, is this: sudo foo | foo2 | foo3 equivalent to this: sudo foo | sudo foo2 | ...
1
vote
1answer
100 views

Find where a bash command is defined or sourced from? [duplicate]

Sometimes I want to know what a command I type into bash actually evaluates to. Usually I can figure out the location of the executable very easily with which. $ which vim /usr/bin/vim But what if ...
4
votes
1answer
166 views

What does the command “$()” do in UNIX?

What does the command $() do in UNIX? Could someone explain what is the significance of $ in the below examples; $(echo var=10) and eval $(echo var=10)
2
votes
1answer
164 views

usage of ! -d in a if condition

When reading the bash script for hadoop management, I found the following one if [ ! -d "${HADOOP_HOME}" ]; then if [ -d "${CDH_HADOOP_HOME}" ]; then what does ! -d "${HADOOP_HOME}" and -d ...
2
votes
1answer
87 views

bash - inherit directory stack in children

If, in my newly created bash, I do: pushd foo pushd bar dirs -l -v I will get something like 0 bar 1 foo 2 old_dir If I then do bash dirs -l -v I get only 0 bar The same thing happens ...
0
votes
1answer
701 views

How to run a shell command in a server?

I am fairly familiar with computers and web stuff but this is a bit out of my comfort zone. I have a shell script (.sh file) I want to run in a Linux server I have one site hosted (the script is a ...
2
votes
2answers
125 views

Discrepancy between the two expansions

If you input the command ls * and echo *, you will notice the remarkable discrepancy between the results. The former recursively includes while the latter totally excludes files in subdirectories. ...
11
votes
3answers
3k views

How to set window size and location of an application on screen via command line?

I want Firefox window to be opened in a specific size, and location on screen using a shell command, for example: firefox myfile.html size 800x600 location bottom-left Is there such a command?
0
votes
1answer
140 views

Execute remote programs and completely detaching it

I need to execute a remote application (named ConnectionManager), which uses the ncurses library, on the remote server launching it from a local pc. ConnectionManager is a program wich use ncurses ...
4
votes
2answers
233 views

The difference between \e and ^[

Gilles wrote: character 27 = 033 = 0x1b = ^[ = \e Demizey wrote: ^[ is just a representation of ESCAPE and \e is interpreted as an actual ESCAPE character Then I also found this line from ...
5
votes
2answers
333 views

Launching an external script with source command

I've been learning shell scripting, by reading good tutorials and reading scripts. I was reading this minecraft init script, and these first lines hit me: if [ -L $0 ] then source `readlink -e ...
10
votes
3answers
24k views

sudo over ssh: no tty present and no askpass program specified

I keep getting this error and have tried several ways discussed online to fix this and none are working for me. I have setup SSH keys so when I run 'ssh newton@host.com' it automatically logs me in, I ...
2
votes
2answers
234 views

How to keep a line from being remembered in the history?

This is for a single line, not a command. I found the way to make it always prevent history for a single command. Thanks. EDIT: Sorry for the poor wording. Single line - For example, if I type, git ...
3
votes
3answers
727 views

Merging two directory without copying the files

Let's say I have as follows : Folder A C1 file a A2 Folder B C1 B2 file b B3 What I want is to merge these two folders, which would give me : Folder C ...
16
votes
6answers
29k views

How can I run a cron command with existing environmental variables?

How can I run a cron command with existing environmental variables? If I am at a shell prompt I can type echo $ORACLE_HOME and get a path. This is one of my environmental variables that gets set in ...
1
vote
2answers
228 views

Shell: Break both if and for loop at once

Shell: Break both if and for loop at once. My script: ip to name resolve code IP=192.168.27.191 hostNameChecker() { if [ `getent hosts $1 | wc -l` -ne 0 ];then HOST_NAME=`hostname` ...
7
votes
5answers
5k views

Run script in a non interactive shell?

I have a cron job that is running a script. When I run the script via an interactive shell (ssh'ed to bash) it works fine. When the script runs by itself via cron it fails. My guess is that it is ...
16
votes
4answers
2k views

What happens if you edit a script during execution?

I have a general question, which might be a result of misunderstanding of how processes are handled in Linux. For my purposes I am going to define a 'script' as a snippet of bash code saved to a text ...
0
votes
1answer
50 views

Executing a script in .zshrc

I'm trying to use z (link) to make navigating a little easier. The problem is that I have the following in my .zshrc file, but it doesn't seem to work: export PATH=$PATH:/home/x/z alias ...
1
vote
1answer
94 views

init-scripts in autoyast to autodeploy Suse Linux server

I'm deploying a base SLES11.1 server using autoyast. What I want to achieve is to install some packages on it after the deployment. So I use the init-script in the autoyast control file. Here is the ...
5
votes
2answers
401 views

How to test if command is alias, function or binary?

I have command foo, how can I know if it's binary, a function or alias?
2
votes
2answers
317 views

Using calibre from the command line

Using calibre from the command line, in debian testing, how can I insert a tag with the syntax being ebook-meta ebook_file --tags rhubarb but for a range of files, but all by the same author ...
4
votes
3answers
1k views

Possible to get SMS/text message notification when process ends/is killed?

There are scripts that will send an e-mail when a server process is finished. However, I do not want to check my email every so often just to see whether a job has finished. Therefore I'd like to get ...
17
votes
8answers
2k views

The most universal scripting language for Linux is?

We are writing scripts for Linux systems, there has been some debate over what would be the most universally Linux present scripting language to use. Bash, SH, Posix? What?
1
vote
1answer
97 views

Access time is not being updated when i run ` ls a ` and then ` stat a`

On CentOS Linux desktop let's create a folder named a. mkdir a Then let's access it ls a and then let's get it's statistics stat a File: `a' Size: 4096 Blocks: 8 IO Block: ...
1
vote
1answer
665 views

The command ` ls -ltu ` fails to list folders/files based on last accessed time

First on your linux desktop create 2 folders. a b Now run this in the terminal ls -ltu the result is drwxr-xr-x 2 root root 4096 Aug 30 20:33 b drwxr-xr-x 2 root root 4096 Aug 30 20:33 a ...
3
votes
3answers
2k views

Remove ^M character from log files

Remove ^M character from log files. In my script I redirect output of my program to a log file. The output of my log file contains some ^M (newline) characters. I need to remove them while running ...
3
votes
4answers
394 views

Why no shebang in .bashrc/.bash_profile?

Simple inquiry: I have just realized that I have never seen a shebang on top of a .bashrc script, which leads me to think the system uses the default shell to source it upon login (${SHELL}). I am ...
-1
votes
1answer
323 views

How to create a GUI in shell script without any third party libs just like setup command [closed]

How to create a GUI in shell script without any third party libs (like setup command)
1
vote
3answers
571 views

wget batch linux file

I am trying to download images from a manufacturer's site using wget. When I run the command from the shell it works fine. But when I run it from a file I am getting a placeholder file. Here is the ...
4
votes
1answer
188 views

Monitor a process in Debian

I want to create a service that monitors the existence of a certain process. I wrote the following shell script: #!/bin/sh while : do w=`ps u -A | grep -P ".+Sl.+/usr/local/MySource/endpoint" -c` ...
20
votes
6answers
22k views

Execute a command once per line of piped input?

I want to run a java command once for every match of ls | grep pattern -. In this case, I think I could do find pattern -exec java MyProg '{}' \; but I'm curious about the general case - is there an ...
2
votes
1answer
176 views

how do I reference a variable in fish shell with a default fallback

What is the fish shell equivalent to the following bash: echo ${TEST:-1} In bash this would print the value of TEST if there was one, or 1 if there was not.
0
votes
3answers
25k views

how to check OS and version using Linux commmand [duplicate]

what is the Linux command to check the server OS and its version? Connected the server using shell.