Ubuntu write shell function error

#!/bin/bashfunction sayIt {   
   echo "hello world"}

sayIt

This returns "hello world" on my laptop, but on my Desktop it returns:

run.sh:3:function not found 
hello world  
run.sh:5:Syntax error:"}" unexpected

Starting with ubuntu 6.10, ubuntu has replaced the previous default bash shell with a dash shell; it appears that /bin/sh links to /bin/dash instead of the traditional /bin/bash.

ubuntu edgy was the first to ship with dash as the default shell, which seems to be influenced by debian. There is an official explanation in the wiki, https://wiki.ubuntu.com/DashAsBinSh, the main reason is that dash is smaller, runs faster, and is POSIX compatible.

But the current problem is that due to the replacement of the shell, many scripts are wrong. After all, many scripts are not 100% POSIX compatible.

It is also mentioned in the wiki, how to change the default shell back to bash, the method is

Execute sudo dpkg-reconfigure dash in terminal

Then select no.

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326760815&siteId=291194637