Questions tagged [sh]

/bin/sh is the POSIX shell. For questions where portability is important. If the question is about .sh files, tag it with scripts instead. On Ubuntu the POSIX shell is symlink to /bin/dash, and [dash-shell] is therefore related to [sh] tag, and both may be used when tagging questions.

237 questions
426
votes
4 answers

What is the difference between #!/bin/sh and #!/bin/bash?

if I write, #!/bin/bash echo "foo" or #!/bin/sh echo "foo" both yields same. I have seen some scripts starting with #!/bin/sh or #!/bin/bash . Is there any difference between them?
Rahul Virpara
  • 11,880
90
votes
3 answers

What is the sh -c command?

I discovered the sh -c command. I found it before I posted here but I can't find any posts from Google that explain it, so I would like to know what it is and what its complete syntax is.
Lan...
  • 951
43
votes
2 answers

Command to perform a recursive chmod to make all .sh files within a directory executable?

Trying to perform a recursive chmod on all the .sh files in a directory to make them executable
Arunava
  • 573
23
votes
2 answers

What is the difference between grep apple file and grep "apple" file?

What is the difference between grep apple file and grep "apple" file ? What does putting the quotation marks do? They both appear to work and do the exact same thing (display same line).
18
votes
1 answer

What does ${0%/*} in shell scripts do?

Sorry if this is a stupid question, but I searched about it without success. What does exactly the second line do ?: #!/bin/sh cd ${0%/*} || exit 1 I know the first is the shebang, the second tries to change directory but the confusing part is…
user545149
15
votes
5 answers

Am I using bash or sh?

I'm connected to a remote shell and many keys aren't working properly such as arrows and the escape key. This answer Arrow keys, tab-complete not working suggested I might be in the wrong shell, so I referenced How to determine the current shell I'm…
Info5ek
  • 261
14
votes
2 answers

Permission denied when running sh file

I am trying to use an sh file to easily start a screen with my minecraft server console. I named this file mc.sh. I have another sh file in the same directory as mc.sh that runs fine. Here is what is in mc.sh: screen -S minecraft java -Xms1024M…
Djm228
  • 143
14
votes
2 answers

Mistakenly modified `/bin/sh'

I had this script: spd-say "Hello, don't forget the trash bin." So it reminded me of what I supposed to do, and I moved it to /usr/local/bin/ and the command trash pronounced the argument,then I set a crontab job , to make it remind me everyday what…
user833907
13
votes
1 answer

sh: 0: Illegal option --

When I try to run the command below in Ubuntu: sudo -n -u contd sh --login -c ". /home/contd/iib-10.0.0.5/server/bin/mqsiprofile;/home/contd/iib-10.0.0.5/common/jdk/jre/bin/java -cp…
12
votes
3 answers

How to create a shortcut for sh file?

I used to launch Android Studio by this steps: Open Android Studio folder. Open terminal there. Confirm sh studio.sh command. Can I lauch Android Studio from the Desktop by the 1 click?
12
votes
6 answers

My Ubuntu server has been infected by a virus kdevtmpfsi

My Ubuntu server has been infected by a virus kdevtmpfsi, I have already done serveral steps to solve this problem, like all of these: https://github.com/docker-library/redis/issues/217 . But it is still coming again and again when docker container…
12
votes
3 answers

Where is the alias for "ll" defined?

I often find myself using ll which is an alias. $ type ll ll is an alias for ls -lh I always wondered where this was defined as it works both on bash , zsh but not on sh : # THIS IS SH $ ll sh: 1: ll: not found
user791290
11
votes
2 answers

What's the problem with Bashisms?

With "Bashism" I mean shell syntax which is only understood by the bash shell and not other shells. If you write a script which gets executed only in environments where /bin/bash exists, then I think avoiding Bashism is just useless and wasting…
guettli
  • 1,765
10
votes
2 answers

Why doesn't auto complete work in my shell?

I am not so into Linux and I have the following doubts: a client provided me an Ubuntu 18.04.3 LTS virtual machine which I access via SSH. (I am using MobaxTerm as SSH client but it should not be the problem.) The shell used is sh . The problem is…
AndreaNobili
  • 4,869
10
votes
2 answers

How does ~/ work?

In the terminal, one way to reference home is by using ~/ . I don't understand how this works, because the output of file ~/ is: /home/admin/: directory and just running ~/ results in: -bash: /home/admin/: Is a directory so what's converting ~/ into…
user8292439
  • 3,888
1
2 3
15 16