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

Export Command History into a Shell Script

Often I have complicated installation procedures to follow, like having to build dependencies for buildtools, to build dependencies for the application I wish to install from source. Once I have done ...
0
votes
1answer
12 views

Insert space at specified position in a file

I have this sample file: 234234|111||J1X0H8|SERP||R|D|666|M 234235|222||J1X0N5|SERP||C||555|M For each line, I need to insert a space after the 3rd character of the 4th column, like so: ...
-4
votes
2answers
42 views

How do I print all env vars beginning with the letter 'T'?

This was an exercise for a course I'm on and I got really stuck at frustrated. I think my main problem is I keep putting the ">>" the wrong way round and then getting stuck in an editor which I don't ...
1
vote
1answer
25 views

Save and restore terminal tabs with custom tabs title

I have a Terminal window with a dozen named tabs open *(gnome-terminal) I would like to save the current configuration and have it restored with names and directories. Is there a way to do this? I've ...
0
votes
2answers
41 views

Untar and gzip from multiple sub directories

I have a directory which consists of multiple sub-directories. Each subdirectory has a tar.gz file which on untar gives two files namely R1.fastq and R2.fastq. I want to untar the tar file and ...
0
votes
1answer
25 views

Opening a socket in Kali Linux using bash scripts

I know how to open a TCP or UDP socket in Ubuntu, with the following command : exec 3<>/dev/tcp/google.com/80 for example: we can open a TCP socket on port 80, but in Kali Linux there's no ...
1
vote
1answer
35 views

Is there a way to change the number of processors a program sees?

Is there any way I can trick a program into thinking the system has fewer processors? To explain: I am debugging a program that creates as many threads as it has processors, using ...
1
vote
1answer
37 views

Read a character from an x-y coordinate on the screen

Is there a way in bash to read a character from an x-y coordinate on the screen? This command would be something similar to cget 12 30 which would return the character at the 12th row and 30th ...
0
votes
2answers
19 views

redirect output from interface?

I am echoing an AT command to a modem interface (/dev/ttyUSB3) and the command runs successfully. For instance the below command works and has an output of OK: echo -e "ATZ\r" > /dev/ttyUSB3 I ...
0
votes
2answers
14 views

The best way to add Unix Shell variables to CURL GET request

Let’s say I use curl –X GET command with the following link: “$WEBSITE_URL/ACTION_NAME/ACTION1;id=$ID?Command=TEST&id1=$ID1&id2=$ID2&id3=$ID3” As you can see, there are some $variables ...
0
votes
0answers
27 views

Pass a function arguments?

How would you make a function that gets arguments? function arg_example { arg "c" # This is imaginary but it would return 'true' if it found the argument -c. did_find_arg=$? # Get the ...
9
votes
5answers
705 views

How to get the last N files in a directory?

I have many files that are ordered by file name in a directory. I wish to copy the final N (say, N=4) files to my home directory. How should I do it? cp ./<the final 4 files> ~/
8
votes
2answers
393 views

Run another command before running the command the user wants to run

Let's say I want to modify the original behavior of the ls tool this way: $ ls Hello World file1 file2 ... How can I do this? When running ls I would like to run another command let's say echo ...
1
vote
2answers
171 views

Why does “grep '.*[s]' file” work and “grep .*[s] file” doesn't?

Comparing grep '.*[s]' file with grep .*[s] file Why do you need quotation marks to let this work properly? In the second case, grep seems trying to inspect every file with a period.
11
votes
3answers
576 views

Terminal vs bash? [duplicate]

I'm on a Mac but I think this is generally Unix-applicable. I'm in the process of learning shell scripting and there's something I seem to be missing. When I'm in the ordinary terminal, I can use ...
0
votes
2answers
12 views

tcpdump filter expression breaks via adb

I installed tcpdump on my Android tablet and am running commands from a root adb shell. I'm working from the tcpdump man page examples, specifically this one: To print all IPv4 HTTP packets to and ...
1
vote
2answers
46 views

BASH: Command not running, special character '�' suddenly appeared (Ubuntu)

When I erroneously type 'ñ' (expecting to type any command) and then remove it and type the correct letter, the output returns the command with a special character attached �, obviously the shell ...
3
votes
2answers
45 views

Why alias inside function does not work?

See the code below: a()(alias x=echo\ hi;type x;alias;x);a I have an alias inside a function, I do not want to change the external environment (that is why I am using () instead of {}), even the ...
0
votes
1answer
19 views

Terminal sandbox commands

I was wondering if there's a way to run shell commands that affect only a certain directory and its subdirectories. I'm using PHP and I want to make an app that allows the user to execute shell ...
2
votes
2answers
58 views

How to return 0 if a pattern is matched from a file? [duplicate]

I have a binary that repacks android kernel (not mkbootimg). I'm making a script to automate the process. I don't want any output on the screen. So I have redirected the output to a file named ...
1
vote
1answer
40 views

Equivalent of Java's String.getBytes() in Unix Shell (Cygwin)

Let's say I convert my string into byte array. byte[] byte sUserID.getBytes(“UTF-8”); //Convert User ID String to byte array Now I need to write a script on Shell that will have exactly the ...
3
votes
2answers
195 views

How to get UUID of filesystem given a path?

I am handed a path of a directory or a file. Which utility/shell script will reliably give me the UUID of the file system on which is this directory/file located? By UUID of file system I mean the ...
1
vote
1answer
13 views

Understanding directory symlinks traversals and the parent directory

Let's say you have directories /dir1 and /dir2/linked, where the later is a symlink to the former. When you cd to linked and pwd, you get the output /dir2/linked. If you then cd .., you'll be put on ...
2
votes
1answer
71 views

bash find: get directory of found file

I have a parent folder named "parent_folder" with a lot of subfolders, in these subfolders is a file named "foo.mp4". I can find these files easily by doing this: mymacbook:parent_folder username$ ...
-2
votes
0answers
26 views

How to create symbolic link to a directory with custom name

I want to create a sym link from the source name TEST to the destination name NAME if i give ln -s TEST /NAME - its going to create the Folder in the /NAME with TEST name but i want to get as NAME ...
0
votes
1answer
30 views

UnixWare 7 fails to pass variable to Linux

I'm new to Bash and I have a problem that find difficult to solve, may be easy for some. I have a really old SCO UnixWare 7 system with no SSH only RSH available. SCO doesn't exist anymore , I ...
1
vote
1answer
25 views

runtime errors, where do they come from?

When a program is executed from the command line (terminal) and there is a runtime error causing the program to seg-fault/coredump where is the runtime error message come from? Is there documentation ...
0
votes
4answers
103 views

How do i change the case (upper and lower case) of strings in my variable?

"Enter test: " read test if [[ $test == "a" ]]; then echo "worked" else echo "failed" fi It's a simple illustration of test i'm doing, but if i enter "A", it will fail, is there anything i ...
-2
votes
2answers
31 views

What is a simple example where the use of the command line is unavoidable or better? [closed]

I want to see a simple example that motivates the use of the Linux command line. Like I want to see an example where the use of the command line will do it in seconds and on GUI , it will take you ...
3
votes
3answers
147 views

Piping a script with “read” to bash

I need to run a script by piping it through bash with wget(rather than running it directly with bash). $ wget -O - http://example.com/my-script.sh | bash It's not working because my script has read ...
13
votes
3answers
754 views

Any reason to use or teach `…` substition for new development?

It is my understanding that the more modern $(...) command substitution syntax is preferred over the old '`'-based syntax, due to easier and less error-prone nesting and escaping syntax. Further, it ...
2
votes
2answers
27 views

“dpkg -l” receives shell wildcard character?

In a bash shell where I have globbing enabled if I execute ls -l *ou*, then shell should pass out.dot and out.png as arguments to ls, i.e. ls never sees the * character. However, looks like in case of ...
1
vote
7answers
174 views

Remove a specific extension from all the files in a directory

I have a couple of files with ".old" extension. How can I remove the ".old" extension without remove the file? I can do it manually but with more work: mv file1.key.old file1.key mv ...
-2
votes
1answer
27 views

How to use both && and || operator in shell script [closed]

chkline="Hello world" lastline1=`tail -1 test4.scrn` lastline2=`tail -1 test5.scrn` if [[ ! -f test.scrn && ! -f test2.scrn && ! -f test3.scrn ]] || [ "$lastline1" != "$chkline" ] || [ "$lastline2" ...
1
vote
1answer
13 views

difference between “ip link set” and “disconnect / reconnect” in the GUI?

I've got an Ubuntu 14.04 guest installed in virtualbox. Often when the host machine changes networks or is suspended and restarted, the guest VM loses network connectivity. I can reliably get it ...
2
votes
2answers
169 views

Can I create, set permissions, and write to a file with a single Unix command?

I want to speed up creation of user accounts on some Linux VMs that I am creating, and wondered if I could simplify the process of writing to the new user's ~/.ssh/authorized_keys or ...
0
votes
3answers
43 views

Diff between (x=100) and { x=100; }?

Can some one please explain the below statements? $ x=50 $ (x=100) #here the code executes only with in the subshell. when subshellexecution done then the x value is returned to its original ...
0
votes
2answers
16 views

How do I tell GCC and Clang to look at /usr/local/cuda for include/libs?

I have installed CUDA on my system, but seems like its files are not being found by libraries that depend on it. What should I append to my .bashrc in order for both GCC and Clang to look on the ...
4
votes
5answers
229 views

How do you interact with a file named “!!”? [duplicate]

Out of rage, I quit vim by using :wq!!!. This created a file named !!. Given that !! references the previous command, attempting to interact with it yields interesting results. I tried rm ./!! and ...
2
votes
1answer
189 views

How to get binary representations of strings in Shell?

I'm using openssl dgst -sha1 -binary to get hash values of my strings in binary format. (I'm using -binary flag because my version of openssl adds "stdout" before each hash value on default output, ...
1
vote
2answers
73 views

How do I get command name of the last executed command?

Example: I type man ls, than I want to get man only. By using !! I can get man ls but how do I get man?
0
votes
2answers
22 views

how to know which device was open

is there any shell command, can let me know, current open device or device already in operation. For example, I use minicom to open a device /dev/ttyUSB0 or /dev/ttyS0, after I use program open this ...
0
votes
0answers
47 views

Bash shell scripting check while comparing 2 files [closed]

I have 2 files File 1 abc cde efg hij jkl File 2 abc ( * ) ( * ) ( * ) -- without the braces efg (*) hij -- without braces () () lmn --- without braces Now, while comparing both files line ...
3
votes
1answer
53 views

Mac OS X combine cp and cat to sequentially copy and rename files in list

I am using a MacBook Pro OS X 2013 model. I have a list of filenames in a text file named list.txt separated by line breaks list.txt exactly like this, but this list is going to be long e.jpeg ...
0
votes
1answer
38 views

timeout pipeline

I want to execute these two timeout command on the same command but with a different time and instructions. So timeout --signal=SIGINT 5s command timeout --signal=SIGKILL 10s command How to append ...
3
votes
2answers
108 views

Assign specific line from a variable to another variable

I would like to take a specific line from a variable to another variable. I tried this but it doesn't work: c="1.apple 2.banna 3.peach" read "Please choose fruit [1-3]:" t a=$c | awk "NR==$t" echo ...
1
vote
1answer
42 views

Using cURL, How can I fetch a numerical string which contains commas and spaces and convert such to a NON COMAFIED string [duplicate]

Example: Google's Outstanding Shares are 670,000,000 and this value is collected in a txt file from Yahoo Finance API using the below script. The issue is; that numbers WITH commas or spaces are ...
2
votes
3answers
92 views

Is it possible to add a function within a function?

function update_profile { echo "1. Update Name" echo "2. Update Age" echo "3. Update Gender" echo "Enter option: " read option case $option in 1) update_name ;; ...
3
votes
1answer
20 views

Redirection with nested commands

I am running a $command, in a instance of a screen, as a different user. It's run by the equivalent of this command (more detailed at bottom): su $USERNAME -c "screen -dmS $SCREENNAME $COMMAND" and ...
4
votes
2answers
66 views

status check for sleep command

I have run sleep command in background as follow , How can I know the status of execution ..? Command sleep 2d ; find /home/disk1/ -exec touch {} \; & How can I know that its executed for 1 ...